Version: 4.2.1

1.1 Syntax Templates

Synopsis: A syntax template is a notation for producing syntax objects that implicitly closes over the bindings in scope where the syntax template occurred. Syntax templates are the mechanism that links scoping with code representations (syntax objects).

Syntax templates are a notation for syntax objects, like quoted forms are a notation for S-expression data. The forms within quote-syntax expressions, syntax and quasisyntax expressions, and the right-hand sides of syntax-rules expressions are syntax templates.

  #'template
  #`(template #,not-part-of-template)
  (quote-syntax template-without-pattern-variables)
  (syntax-rules ()
    [pattern1 template1]
    [pattern2 template2] ...)

Syntax templates are the foundation of the macro system’s mechanism for tracking binding information (the part of hygiene often called referential transparency). Unlike quoted S-expressions, the syntax objects produced by syntax templates carry with them binding information from the syntax template’s context. Consequently, macro writers reason about the binding information carried by syntax objects in terms of the context of the syntax template (see Lexical Context Analysis).