Find a syntax example, read its result, and follow its link for the full rules. Use the cards as a reference while writing your own program.
Run each card's complete example separately in the Playground. The result shown below each example is the value displayed there.
Literals and comments
value ; comment(list 42 #t "tea" #\T 'ready)
; the comment is ignoredResult
(42 #t "tea" #\T ready)Numbers, booleans, strings, and characters can be written directly.
The quote in 'ready makes ready a symbol value.
A semicolon starts a comment that continues to the end of the line.
Calls and nesting
(procedure argument ...)(+ 10 (* 2 3))Result
16The inner call (* 2 3) returns 6, so the outer call adds 10 and 6.
In a procedure call, the first expression selects the procedure.
That expression and the arguments are evaluated from left to right.
Names and local values
define · let · let* · letrec(let ((trim-width 20) (bleed 3))
(+ trim-width bleed))Result
23let gives local names to values. Here, trim-width is 20 and bleed is 3.
The initial value expressions use the surrounding scope, so neither can use the other's new name.
Use define for a top-level name.
Use let* when a later local value needs an earlier name, and letrec for recursive local definitions.
Named procedures and lambda
(define (name x) body) · (lambda (x) body)(define (double n) (* n 2))
(double 6)Result
12define names a procedure and its arguments. Here, double multiplies its argument by 2.
A procedure is itself a value. You can create one without naming it by using lambda.
Conditions
if · cond · case · and · or(if (< 1 2) 'next-page 'keep)Result
next-pageif selects 'next-page because one remaining line is less than two.
cond checks several conditions in order. case selects by matching a value.
and and or stop when the result is known. Only #f counts as false.
Quoted data and lists
'datum · (list value ...)(list 'decision 'allow)Result
(decision allow)A quote keeps data from being evaluated. Here, 'decision and 'allow are symbol values.
list evaluates its arguments and puts their values into a new list.
Strings, vectors, and bytes
"text" · #(value ...) · #u8(byte ...)(list (string-length "Lispex")
(vector-ref #(red green blue) 1))Result
(6 green)string-length counts the characters in "Lispex".
vector-ref selects an element by an index starting at zero, so index 1 selects green.
Strings hold Unicode text. Vectors hold ordered elements and can be changed in the current language profile.
Bytevectors hold values from 0 through 255 and cannot be changed.
List processing and recursion
recursion · map · filter · fold · apply(map (lambda (n) (* n 10)) '(1 2 3))Result
(10 20 30)map calls the procedure for each list element and returns the results in a list.
filter selects elements, and folds combine them into an accumulated value.
apply calls a procedure with arguments from a list.
A recursive procedure calls itself. Tail calls let repeated recursive calls run without growing the call stack.
Find the next detail
| Question | Continue with |
|---|---|
| How can procedures share a value that changes? | Bindings, Cells, and Mutation and Closures |
Why does 1/3 stay exact while (/ 1.0 3) is inexact? | Exact Numbers and Approximations |
| How can one computation return two results? | Multiple Values |
| Which recursive calls use constant stack? | Proper Tail Calls |
| How can a program leave a computation early? | Continuations and dynamic-wind |
| How are infinite work and huge output stopped? | Determinism and Resources |
Consult Reference for Reading Code and Basic Syntax Forms for exact accepted tokens and form shapes. Revisit the Learning Path when you want a guided sequence.