Syntax at a Glance

Scan the everyday Lispex syntax on one page, with tiny examples, observed results, and direct links to the full manual.

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
LISPEX
(list 42 #t "tea" #\T 'ready)
; the comment is ignored

Result

OUTPUT
(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.

Read the source and reader manual

Calls and nesting

(procedure argument ...)
LISPEX
(+ 10 (* 2 3))

Result

OUTPUT
16

The 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.

Learn evaluation order

Names and local values

define · let · let* · letrec
LISPEX
(let ((trim-width 20) (bleed 3))
  (+ trim-width bleed))

Result

OUTPUT
23

let 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.

Learn names and scope

Named procedures and lambda

(define (name x) body) · (lambda (x) body)
LISPEX
(define (double n) (* n 2))
(double 6)

Result

OUTPUT
12

define 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.

Learn procedures and argument counts

Conditions

if · cond · case · and · or
LISPEX
(if (< 1 2) 'next-page 'keep)

Result

OUTPUT
next-page

if 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.

Choose a conditional form

Quoted data and lists

'datum · (list value ...)
LISPEX
(list 'decision 'allow)

Result

OUTPUT
(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.

Learn data and aggregates

Strings, vectors, and bytes

"text" · #(value ...) · #u8(byte ...)
LISPEX
(list (string-length "Lispex")
      (vector-ref #(red green blue) 1))

Result

OUTPUT
(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.

Open the text and byte reference

List processing and recursion

recursion · map · filter · fold · apply
LISPEX
(map (lambda (n) (* n 10)) '(1 2 3))

Result

OUTPUT
(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.

Learn list processing

Find the next detail

QuestionContinue 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.