17.4 Definition Macros
space | |
value | |
A compile-time value that identifies the same space as defn. See also SpaceMeta.
definition | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| ||||||||||||||||||||||||
|
The expansion result must be a sequence of groups that are inlined in place of the definition-macro use.
The options in the macro body must be distinct. The ~op_stx option, if present, binds an identifier for a use of the macro (which cannot be matched directly in the pattern, since that position is used for the name that defn.macro binds). The ~all_stx option binds an identifier to the input that is matched by the prefix_macro_pattern, which includes the identifier or operator that ~op_stx would capture. The ~name_prefix option binds an identifier to a symbol or #false for a name prefix created by an enclosing namespace; this prefix should not be used for the binding, but it should be used for run-time reports, such as as naming the origin of a run-time error.
Using | alternatives, a single definition can have any number of patterns, which are tried in order. The defined_name must be the same across all cases.
> defn.macro 'enumerate:
$lhs
...':
...'
> enumerate:
a
b
c
> b
1
definition | ||||||
|
The macro result is two values: a sequence of groups to splice in place of the sequence-macro use, and a sequence of groups that represent the tail of the definition context that was not consumed.
> defn.sequence_macro 'reverse_defns
$defn1
$defn2
$tail
...':
> reverse_defns
seq_x
11
syntax class | ||
|
Syntax class that matches only groups that start with an identifier that is bound as a definition form.
Unlike expr_meta.Parsed, defn_meta.Group does not parse the definition form, because the form normally needs to be parsed within a definition context. This syntax class can be used to distinguish definitions from other forms that need to be treated differently in some context.
syntax class | ||
|
Syntax class that matches only groups that starts with an identifier that is bound as a definition-sequence form.
Similar to expr_meta.pack_s_exp, but for definitions.