On this page:
splicing-let
splicing-letrec
splicing-let-values
splicing-letrec-values
splicing-let-syntax
splicing-letrec-syntax
splicing-let-syntaxes
splicing-letrec-syntaxes
splicing-letrec-syntaxes+ values
splicing-local
splicing-syntax-parameterize
Version: 4.2.1

11.6 Local Binding with Splicing Body

The bindings documented in this section are provided by the scheme/splicing library, not scheme/base or scheme.

Like let, letrec, let-values, letrec-values, let-syntax, letrec-syntax, let-syntaxes, letrec-syntaxes, letrec-syntaxes+values, and local, except that in a definition context, the body forms are spliced into the enclosing definition context (in the same way as for begin).

Examples:

  > (splicing-let-syntax ([one (lambda (stx) #'1)])
      (define o one))
  > o

  1

  > one

  reference to undefined identifier: one

When a splicing binding form occurs in a top-level context or module context, its local bindings are treated similarly to definitions. In particular, if a reference to one of the splicing form’s bound variables is evaluated before the variable is initialized, an unbound variable error is raised, instead of the variable evaluating to the undefined value. Also, syntax bindings are evaluated every time the module is visited, instead of only once during compilation as in let-syntax, etc.

Example:

  > (splicing-letrec ([x bad]
                      [bad 1])
      x)

  reference to undefined identifier: bad.3

Like syntax-parameterize, except that in a definition context, the body forms are spliced into the enclosing definition context (in the same as as for begin), as long as the body forms are valid in an internal-definition context. In particular, require and provide forms cannot appear in the body of splicing-syntax-parameterize, even if splicing-syntax-parameterize is used in a module body. In a definition context, the body of splicing-syntax-parameterize can be empty.

Examples:

  > (define-syntax-parameter place (lambda (stx) #'"Kansas"))
  > (define-syntax-rule (where) `(at ,(place)))
  > (where)

  (at "Kansas")

  > (splicing-syntax-parameterize ([place (lambda (stx) #'"Oz")])
      (define here (where)))
  > here

  (at "Oz")