17.16 Syntax Parameters
A syntax context parameter (or just syntax parameter) is analogous to a context parameter, but for macro-expansion contexts instead of evaluation contexts. While a context parameter communicates to a more nested evaluation context, even if that context is not lexically nested, a syntax parameter communicates to a more nested expansion position, where nested expression may have been macro-introduced instead of being lexically nested in the original source. For example, this is implemented through a syntax parameter that allows its meaning to be adapted to an enclosing method, even when a use of this is macro-introduced in the method body.
A syntax parameter is not useful on its own, but it can work in concert with one or more space-specific macros that use it. Bind a new syntax parameter using syntax_parameter.bridge, and adjust a syntax parameter’s binding in the remainder of a definition context using syntax_parameter.relet.
definition | |||
|
syntax_parameter.bridge today_name:
"Thursday"
expr.macro 'today':
'$(syntax_parameter_meta.lookup('today_name'))'
fun say_today():
today
expr.macro 'say_today_here':
'today'
> today
"Thursday"
> block:
syntax_parameter.relet today_name:
"Friday"
[today,
say_today(),
say_today_here]
["Friday", "Thursday", "Friday"]
> today
"Thursday"
definition | |||
|
See syntax_parameter.bridge for an example.