Core Forms

The core that the program running your rule handles directly is quotation, variable reference, if, sequencing, lambda, application, assignment, definition, lexical binding, and fixed control nodes.

See it run

LISPEX
((lambda (x) (if #t x 0)) 42)

Observed result

OUTPUT
42

How to reason about it

  • if has a mandatory else arm, and begin and procedure bodies preserve left-to-right order.
  • lambda supports fixed and dotted formals. set! mutates an existing cell, and define updates or creates a top-level cell.
  • quote returns immutable literal data, and the runtime does not evaluate quoted elements.
  • module is written (module name (export id ...) (import name ...) body ...) and may only sit at top level. Nest it inside another form and you get E130. The export and import clauses come before the body.
  • A module header 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
42

Form contracts

FormArguments / evaluationResult or fault
quote1 datum, no element evaluationimmutable datum
iftest, consequent, alternate, with the test firstthe values from the selected branch. E320 if the test is not one value
lambdaformals plus 1..N body formsclosure. E302 when applied with the wrong number of arguments
set!a name and a single-value expression on the rightzero values. E303 if the name is unbound
let / letrecbinding list plus 1..N body formsthe values from the last body form. E321 on an uninitialized letrec read
modulea name, 0..2 header clauses, 1..N body formsthe 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.

Derived Forms · Expressions and Evaluation Order