Special forms
A special form is a head the compiler handles itself. When a form’s head
names one, the compiler emits bytecode for it directly, following the
form’s own rules for which arguments are evaluated and when. Every other
head in call position is a runtime call. Each page below gives the
form’s symbol, syntax, behaviour, and examples; the surface names most
programs write, if, when, set!, class, are
macros that lower to these.
The compiler binds each special under its compile/ name, and the
short name is how a program uses it. How (foo ...) decides between a
special, a macro, and a call is in
Name resolution and prefixes.
Definition and binding
Form |
Does |
|---|---|
Bind a name in the current scope, with an optional type, or several names by unpacking |
|
The Scheme-layer spelling of |
|
Bind a name at the module from any depth; what |
|
Bind the names of a pattern in the current scope; what |
|
Bind the names of a pattern at the module; what |
|
A named function value that is not bound |
|
An anonymous function value; formals, defaults, rest collectors, annotations, by-ref |
|
Lexical bindings for a body; named |
|
Lexical bindings that may refer to each other |
|
Store into an existing binding; the special under |
|
Store into several bindings by unpacking |
|
Bind a name to a ref |
|
The ref of a variable; the special under |
|
Read through a ref |
|
Read a binding and clear it |
|
Delete a binding |
|
The module namespace; the current scope’s namespace, or an object’s |
|
Read a dynamic parameter; rebind parameters for a body |
Control flow
Form |
Does |
|---|---|
Run forms in order; the value is the last |
|
The first clause whose test is true; what layout |
|
Branch on equality against candidates |
|
Destructure against patterns; see Match patterns |
|
Short-circuit conjunction and disjunction |
|
Loop while a test is true, with an |
|
Loop over an iterable, with destructuring and an |
|
Leave a loop, with an optional value; start the next iteration |
|
Leave a function; several values return a tuple, keywords a |
|
Handle exceptions, with |
|
Raise an exception, or re-raise the current one |
|
Internal forms that |
Objects, attributes, and items
Form |
Does |
|---|---|
Read, store, delete an attribute; |
|
A ref to an attribute; take and delete; update in place |
|
Read, store, delete a subscript; |
|
A ref to a subscript; take and delete; update in place |
|
Update a variable in place; the special under |
|
Call a value; forces a runtime call past a same-named macro |
|
Call a method by name; |
|
Build a class value without binding a name; what |
|
Type tests; a tuple as the second operand tests several types |
|
String conversion; |
|
Build a list or tuple; append to a list |
Operators
Form |
Does |
|---|---|
|
Equality, chained over any number of operands |
Ordering, chained |
|
Aliases for |
|
Exponentiation with an optional modulus |
|
Membership and identity, each with a |
|
|
The unary and inspection operators |
The arithmetic, bitwise, and unary operators, constant folding, and the comparison table |
Pairs and quoting
Form |
Does |
|---|---|
Build a pair chain; its first element; its rest |
|
Build a bracket pair chain; a proper bracket list |
|
A form as data; |
|
A form as data, keeping hygiene marks; |
|
A template; |
|
A template keeping hygiene marks; |
|
The reader shorthands |
Async, generators, and continuations
Form |
Does |
|---|---|
Await a held awaitable; bare |
|
Generator and coroutine suspension; delegation |
|
Context managers, lexical and dynamic-extent |
|
Before and after thunks around a body, rerun across continuation jumps |
|
Delimited continuations |
|
Undelimited continuations, from the Scheme form down to the raw capture |
Modules
Form |
Does |
|---|---|
Import a module; |
|
Import names from a module, with aliases |
|
Bind a module’s public names, at module level only |
|
Import a feature with all its facets, a macro together with its runtime sibling |
Macro definition and the compiler
Form |
Does |
|---|---|
Template transformers, by rule list and by named spec |
|
Procedural transformers |
|
Transformers that receive the compiler and emit bytecode |
|
The arm used when a syntax name appears as a lone atom |
|
The |
|
Expand a fenced foreign literal through its handler |
|
Inject bytecode directly |
Patterns and hygiene
Many specials declare their shape with koskari.matcher
patterns, and a form that fits none of a special’s patterns fails with
SyntaxMatchError at compile time. The transformer forms share one
matcher and one hygiene model; see
Macros and hygiene and
koskari.hygiene.