See it run
LISPEX
((lambda (x) (if #t x 0)) 42)Observed result
OUTPUT
42How to reason about it
ifhas a mandatory else arm, andbeginand procedure bodies preserve left-to-right order.lambdasupports fixed and dotted formals.set!mutates an existing cell, anddefineupdates or creates a top-level cell.quotereturns immutable literal data, and the runtime does not evaluate quoted elements.moduleis written(module name (export id ...) (import name ...) body ...)and may only sit at top level. Nest it inside another form and you get E130. Theexportandimportclauses come before the body.- A
moduleheader is checked and then discarded, and the body is flattened outward. It does not create a namespace. Do not expect it to hide anything. That is why(f 21)below is called from outside the module.
LISPEX
(module doubling
(export twice)
(define (twice x) (* x 2)))
(twice 21)Observed result
OUTPUT
42Form contracts
| Form | Arguments / evaluation | Result or fault |
|---|---|---|
| quote | 1 datum, no element evaluation | immutable datum |
| if | test, consequent, alternate, with the test first | the values from the selected branch. E320 if the test is not one value |
| lambda | formals plus 1..N body forms | closure. E302 when applied with the wrong number of arguments |
| set! | a name and a single-value expression on the right | zero values. E303 if the name is unbound |
| let / letrec | binding list plus 1..N body forms | the values from the last body form. E321 on an uninitialized letrec read |
| module | a name, 0..2 header clauses, 1..N body forms | the body, flattened outward. E130 anywhere but top level |
A common mistake
Convenience forms written as shorthand belong to the derived-form reference.
Keep going
Derived Forms holds the shorthand that normalizes into these shapes, and the manual explains when each subexpression runs.