12.6 Local Binding with Splicing Body

► |  | The Racket Reference

1 | Language Model
2 | Notation for Documentation
3 | Syntactic Forms
4 | Datatypes
5 | Structures
6 | Classes and Objects
7 | Units
8 | Contracts
9 | Pattern Matching
10 | Control Flow
11 | Concurrency and Parallelism
12 | Macros
13 | Input and Output
14 | Reflection and Security
15 | Operating System
16 | Memory Management
17 | Unsafe Operations
18 | Running Racket
| Bibliography
| Index

▼ | 12 | Macros

12.1 | Pattern-Based Syntax Matching
12.2 | Syntax Object Content
12.3 | Syntax Object Bindings
12.4 | Syntax Transformers
12.5 | Syntax Parameters
12.6 | Local Binding with Splicing Body
12.7 | Syntax Object Properties
12.8 | Syntax Taints
12.9 | Expanding Top-Level Forms
12.10 | Serializing Syntax
12.11 | File Inclusion
12.12 | Syntax Utilities
12.13 | Phase and Space Utilities

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-parameterize
splicing-syntax-parameterize

top contents ← prev up next →

### 12.6 Local Binding with Splicing Body🔗ℹ

(require racket/splicing) | package: base

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

> syntax splicing-let
> syntax splicing-letrec
> syntax splicing-let-values
> syntax splicing-letrec-values
> syntax splicing-let-syntax
> syntax splicing-letrec-syntax
> syntax splicing-let-syntaxes
> syntax splicing-letrec-syntaxes
> syntax splicing-letrec-syntaxes+values
> syntax splicing-local
> syntax splicing-parameterize

Like let (not named let), letrec, let-values, letrec-values, let-syntax, letrec-syntax, let-syntaxes, letrec-syntaxes, letrec-syntaxes+values, local, and parameterize, 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
> one: undefined;
> cannot reference an identifier before its definition
> in module: top-level

When a splicing binding form occurs in a top-level context or module context, its local bindings are treated similarly to definitions. In particular, 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)
> bad.1: undefined;
> cannot reference an identifier before its definition
> in module: top-level

If a definition within a splicing form is intended to be local to the splicing body, then the identifier should have a true value for the 'definition-intended-as-local syntax property. For example, splicing-let itself adds the property to locally-bound identifiers as it expands to a sequence of definitions, so that nesting splicing-let within a splicing form works as expected (without any ambiguous bindings).

Changed in version 6.12.0.2 of package base: Added splicing-parameterize.

> syntax splicing-syntax-parameterize

Like syntax-parameterize, except that in a definition context, the body forms are spliced into the enclosing definition context (in the same way as for begin). In a definition context, the body of splicing-syntax-parameterize can be empty.

Note that require transformers and provide transformers are not affected by syntax parameterization. While all uses of require and provide will be spliced into the enclosing context, derived import or export specifications will expand as if they had not been inside of the splicing-syntax-parameterize.

Additionally, submodules defined with module* that specify #f in place of a module path are affected by syntax parameterization, but other submodules (those defined with module or module* with a module path) are not.

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")

Changed in version 6.11.0.1 of package base: Modified to syntax parameterize module* submodules that specify #f in place of a module path.

top contents ← prev up next →