On this page:
syntax_  parameter.bridge
syntax_  parameter.relet
8.12

7.15 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 lexiecally 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 id_name:

  body

  ...

Defines a new syntax parameter as id_name. The result of the expand-time body sequence is the initial compile-time value of the syntax parameter.

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

syntax_parameter.relet 'id_name':

  body

  ...

Binds the syntax parameter id_name (which must be defined already) to the compile-time result of the body sequence. The binding applies to all subsequent forms in the enclosing definition context, hence it’s a “re-let” of the binding.

See syntax_parameter.bridge for an example.