On this page:
macro
replace_  scopes

10 Macros🔗ℹ

definition

macro 'id pattern':

  def local_id = expr

  ...

  'template'

 

definition

macro '$left_id op pattern':

  def local_id = expr

  ...

  'template'

 

definition

macro

| 'id pattern':

    def local_id = expr

    ...

    'template'

| ...

 

definition

macro

| '$left_id op pattern':

    def local_id = expr

    ...

    'template'

| ...

Defines id as a macro that matches a use of id followed by a match to one of the patterns, or defines op as a macro that matches an expression followed by a use of op and a match to one of the patterns. In each case, the expansion of the macro is given by template. A pattern or template can include uses of $ to bind and reference pattern variables, including left_id as a pattern variable for a case of defining op.

In template, $ can only be followed by a pattern variable or a compile-time expression. A compile-time expression can be any of the locally defined local_ids, it can be a template written using quotes (which is implicitly a use of #%quotes), or it can be a replace_scopes form. The expr for a local_id must also be a compile-time expression.

See Syntax Objects, Patterns, and Templates for general information about patterns and templates.

macro 'let $id = $rhs:

         $body':

  'block:

     def tmp = $rhs

     block:

       def $id = tmp

       $body'

> let x = 1:

    let x = x + 2:

      x

- Int

3

Available only in compile-time positions within macro.

The replace_scopes form returns a syntax object like the one produced by the first stx_expr, but with the scopes of the syntax object produced by the second stx_expr. A syntax object’s scopes correspond to a lexical context and determine which other identifiers it can bind or reference. Each stx_expr is also a compile-time expression.