Core Expander Syntax
Gerbil is a Meta-Scheme that bases the expansion of forms on the context present while expanding. When expanded by the compiler or interpreter a form could have very different meanings depending on the current-expander-context.
These syntactic forms come from the root context, which is the parent context of all syntactic contexts in Gerbil. They are not a part of the core prelude per se, but they are documented here for completeness.
Top Forms
begin
(begin form ....)
begin-syntax
(begin-syntax form ...)
Like begin, but at syntax phase phi +1.
begin-annotation
(begin-annotation annotation form ...)
Effect the declarations in annotation in the scope of the body.
Not implemented yet.
import
(import import-spec ...)
<import-spec>:
(phi: dphi import-spec ...) ; import at differential phase; phi: +1 imports for syntax
(begin: import-spec ...) ; group together import specs
(runtime: module-path) ; import a module as runtime dependency (no bindings)
(spec: module-path phi name src-phi src-name) ; fully specified import
(macro macro-arg ....) ; expand import expander `macro` with `macro-arg ...`
module-path ; import a module
<module-path>:
string ; source module path, relative to the current source
bound-identifier ; module bound in the current context
library-path ; library module path
relative-library-path ; relative library module path
<library-path>:
':' symbol ['/' symbol]* ; library module path, with `/` as file system separator
<relative-library-path>:
'./' symbol ['/' symbol]* ; library module path relative to the current library module
'../' ['../']* symbol ['/' symbol]* ; relative library module path with package traversal
Imports bindings to the current syntactic context. Must appear at top or module context.
module
(module id module-body ...)
Creates a module and binds it to id. The module may be defined at top context for
a top module or as a nested module inside another module.
export
(export export-spec ...)
<export-spec>:
#t ; export all defined bindings at current phi
(phi: dphi export-spec ...) ; export a differential phase; phi: +1 exports for syntax
(begin: export-spec ...) ; group together export specs
(spec: phi id name) ; export `id` at phase `phi` with name `name
(rename: id name) ; export `id` with name `name`
(import: module-path ...) ; export all imports from modules specified by `module-path ...`
(macro macro-arg ...) ; expand export expander `macro` with `macro-arg ...`
id ; export `id` with the same name
Exports bindings from the current module.
declare
(declare declaration ...)
Make declarations that the compiler finds useful
include
(include path)
Include the contents of path, wrapped with a begin.
cond-expand
(cond-expand
(feature body ...) ...
[(else body ...)])
<feature>:
(and feature ...) ; boolean and of `feature ...`
(or feature ...) ; boolean or of `feature ...`
(not feature) ; negation of feature
id ; satisfied if `id` is bound as a feature identifier OR as a module
,expr ; satisfied if `expr` evaluates to true at expand-time
(defined id ...) ; satisfied if every `id` is bound as a regular identifier
Conditionally expands the body for the first satisfied feature
as if by (begin body ...).
Gerbil provides a few extensions compared to the feature defined in SRFI-0.
First, in SRFI-0, cond-expand can only appear in a top-level form;
Gerbil supports cond-expand anywhere an expression is allowed.
Second, an arbitrary expand-time expression expr can be provided as
(unquote expr) (or equivalently ,expr), satisfying the condition
if it evaluates to a true boolean.
Third, a list of identifiers can be specified with (defined id ...),
the condition being satisfied if every specified identifier is bound.
Fourth, a specified identifier may be satisfied if bound as a feature,
but also if bound as a module (as defined with the (module ...) special form).
BEWARE, though that in a future release we may refactor this behavior and
instead add separate syntax to check for such locally bound modules,
for globally imported or available modules, etc.
We recommend you use ,expr syntax and contact the implementers
if you rely on such syntax.
Otherwise, the form is processed as in SRFI-0:
An identifier specifies a condition satisfied if the identifier is bound in a special feature identifier namespace. You can query available features with
(features).The boolean combinator
(and feature ...)is satisfied if every specified feature is satisfied.The boolean combinator
(or feature ...)is satisfied if any specified feature is satisfied.The boolean combinator
(not feature)is satisfied if the specified feature is not satisfied.A last clause
elseis always satisfied.
provide
(provide id ...)
Binds id ... as features provided by a module.
define-values
(define-values (id ...) expr)
define-syntax
(define-syntax id expr)
define-alias
(define-alias id alias-id)
Defines a syntactic alias for id to be the same as alias-id
extern
(extern id ...)
(extern namespace: [namespace-id | #f] id ...)
Create runtime bindings for id, with the symbols bound at runtime through an
external mechanism (eg builtin or defined at a foreign library).
Expressions
lambda%
(lambda% lambda-formals body ...)
Plain old Scheme lambda, without optional and keyword argument support
case-lambda
(case-lambda (lambda-formals body ...) ...)
let-values letrec-values letrec*-values
(let-values (((id ...) expr) ...) body ...)
(letrec-values (((id ...) expr) ...) body ...)
(letrec*-values (((id ...) expr) ...) body ...)
let-syntax letrec-syntax
(let-syntax ((id syntax-expr) ...) body ...)
(letrec-syntax ((id syntax-expr) ...) body ...)
if
(if test-expr then-expr else-expr)
(if test-expr then-expr)
quote
(quote datum)
quote-syntax
(quote-syntax id)
Quote an identifier id, capturing its syntactic context.
Expander Hooks
(%%app rator rand ...)
(%%ref id)
(%%begin-module body ...)
Special expander indirection hooks; explained elsewhere in the documentation.
Reserved Syntactic Tokens
The following widely used syntactic tokens are defined as reserved expanders:
_ ... else => unquote unquote-splicing unsyntax unsyntax-splicing