1 Welcome to PLT Scheme
2 Scheme Essentials
3 Built-In Datatypes
4 Expressions and Definitions
5 Programmer-Defined Datatypes
6 Modules
7 Input and Output
8 Contracts
9 Classes and Objects
10 Exceptions and Control
11 Iterations and Comprehensions
12 Regular-Expression Matching (Regexps)
13 Pattern Matching
14 Quasiquoting
15 Units (Higher-Order Modules)
16 Threads
17 Syntactic Extension (Macros)
18 Reflection and Dynamic Evaluation
19 Reader Extension
20 Security
21 Memory Management
22 Performance
23 Foreign-Function Interface (FFI)
24 Scripts
25 Graphical User Interfaces (GUIs)
26 More Tools
Index
On this page:
14.1 Escapes: quasiquote, unquote, and unquote-splicing
14.2 Abbreviating with `, ,, and ,@

contents

 index

← prev  up  next →

 

14 Quasiquoting

[Explain why...]

14.1 Escapes: quasiquote, unquote, and unquote-splicing

The quasiquote form is similar to quote:

(quasiquote datum)

However, for each (unquote expr) that appears within the datum, the expr is evaluated to produce a value that takes the place of the unsyntax sub-form.

Examples:

  > (quasiquote (1 2 (unquote (+ 1 2)) (unquote (- 5 1))))

  (1 2 3 4)

The unquote-splicing form is similar to unquote, but its expr must produce a list, and the unquote-splicing form must appear in a context that produces either a list of vector. As the name suggests, the resulting list spliced into the context of its use.

Examples:

  > (quasiquote (1 2 (unquote-splicing (list (+ 1 2) (- 5 1))) 5))

  (1 2 3 4 5)

If a quasiquote form appears within an enclosing quasiquote form, then the inner quasiquote effectively cancels one layer of unquote and unquote-splicing forms, so that a second unquote or unquote-splicing is needed.

14.2 Abbreviating with `, ,, and ,@

 

contents

 index

← prev  up  next →