See it run
((lambda (x) (if #t x 0)) 42)Observed result
42lambda creates a procedure with parameter x. The call binds x to 42. if tests #t and evaluates only x, so the result is 42. It skips the other branch, 0.
Run the examples in the playground. Each returns 42.
Read the core forms
A form is a piece of program syntax. Core forms are the forms Lispex evaluates directly. They include quotation, variable reference, if, sequencing, lambda, calls, assignment, definition, lexical binding, and control forms.
ifrequires a test and both branches.beginand procedure bodies run from left to right.lambdaaccepts a fixed parameter list or a dotted list for extra arguments.set!changes an existing cell, the storage location associated with a name.definecreates or updates a top-level cell.quotereturns immutable data without evaluating its elements. For example,'(+ 1 2)returns the list(+ 1 2).
A datum is one item of data, such as a number, symbol, or list. The quote row below uses this term.
Define a module at top level
(module doubling
(export twice)
(define (twice x) (* x 2)))
(twice 21)Observed result
42The call (twice 21) works outside the module because its body becomes part of the surrounding top level. The definitions share that scope. The module name does not create a separate namespace.
Write a module as (module name (export id ...) (import name ...) body ...). Its optional export and import clauses precede the body. Lispex checks these headers, discards them, and places the body forms at top level. Nesting module inside another form raises E130.
Syntax, evaluation, and results
| Form | Arguments / evaluation | Result or fault |
|---|---|---|
quote | one datum; elements are not evaluated | immutable datum |
if | test, true branch, false branch; evaluates the test first | values from the selected branch; E320 if the test does not produce exactly one value |
lambda | parameters and one or more body forms | closure; E302 when called with the wrong number of arguments |
set! | a name and an expression producing one value | zero values; E303 if the name is unbound |
let / letrec | binding list and one or more body forms | values from the last body form; E321 when reading an uninitialized letrec binding |
module | name, zero to two header clauses, one or more body forms | body forms placed at top level; E130 elsewhere |
A closure is a procedure that keeps access to the bindings where it was created. See Procedures for parameters and Bindings for cells and scope. With lexical binding, program structure determines where a name is looked up.
Keep going
Lispex converts shorthand into core forms before execution. This step is called normalization. Syntax That Expands into Basic Forms describes those conversions. Expressions and Evaluation Order explains when each part runs.