You are looking at historical revision 35116 of this page. It may differ significantly from its current revision.

Module (chicken syntax)

This module has support for syntax- and module handling. This module is used by default, unless the program is compiled with the -explicit-use option.

Macro transformers

Macro transformers are procedures you can use in a define-syntax context to register a procedure that can transform s-expressions into other s-expressions. Only use these when you need to break hygiene in a controlled way; for many use cases syntax-rules is more appropriate, as it offers stronger guarantees of hygiene and is more high-level.

er-macro-transformer

[procedure] (er-macro-transformer TRANSFORMER)

Returns an explicit-renaming macro transformer procedure created from the procedural macro body TRANSFORMER, which is a procedure of three arguments.

Implementation note: this procedure currently just returns its argument unchanged and is available for writing low-level macros in a more portable fashion, without hard-coding the signature of a transformer procedure.

ir-macro-transformer

[procedure] (ir-macro-transformer TRANSFORMER)

This procedure accepts a reverse syntax transformer, also known as an implicit renaming macro transformer. This is a transformer which works almost like er-macro-transformer, except the rename and compare procedures it receives work a little differently.

The rename procedure is now called inject and instead of renaming the identifier to be resolved in the macro's definition environment, it will explicitly inject the identifier to be resolved in the expansion environment. Any non-injected identifiers in the output expression produced by the transformer will be implicitly renamed to refer to the macro's environment instead. All identifiers in the input expression are of course implicitly injected just like with explicit renaming macros.

To compare an input identifier you can generally compare to the bare symbol and only free identifiers will match. In practice, this means that when you would call e.g. (compare (cadr expression) (rename 'x)) in an ER macro, you simply call (compare (cadr expression) 'x) in the IR macro. Likewise, an unhygienic ER macro's comparison (compare sym 'abc) should be written as (compare sym (inject 'abc)) in an IR macro.

Expanding macros

expand

[procedure] (expand X)

If X is a macro-form, expand the macro (and repeat expansion until expression is a non-macro form). Returns the resulting expression.

Macro helper procedures

begin-for-syntax

[syntax] (begin-for-syntax EXP ...)

Equivalent to (begin EXP ...), but performs the evaluation of the expression during macro-expansion time, using the macro environment rather than the interaction environment.

You can use this to define your own helper procedures that you can call from a syntax transformer.

syntax

[procedure] (syntax EXPRESSION)

This will quote the EXPRESSION for use in a syntax expansion. Any syntactic information will be stripped from the EXPRESSION.

strip-syntax

[procedure] (strip-syntax EXPRESSION)

Strips all syntactical information from EXPRESSION, returning a new expression where symbols have all context-information removed.

You should use this procedure whenever you want to manually construct new identifiers, which an unhygienic macro can insert. In some cases it does not appear to be necessary to strip context information when you use the macro, but you still should do it. Sometimes identifiers will not have been renamed (most often at toplevel), but there may be other contexts in which identifiers will have been renamed.

get-line-number

[procedure] (get-line-number EXPR)

If EXPR is a pair with the car being a symbol, and line-number information is available for this expression, then this procedure returns the associated source file and line number as a string. If line-number information is not available, then #f is returned. Note that line-number information for expressions is only available in the compiler.

syntax-error

[procedure] (syntax-error [LOCATION] MESSAGE ARGUMENT ...)

Signals an exception of the kind (exn syntax). Otherwise identical to error.


Previous: Module (chicken string)

Next: Module (chicken tcp)