# macro/quote
Build code from a template while preserving `$param` references as
literal symbols. Use `[macro/unquote ...]` inside to selectively substitute
parameters.
`macro/quote` is the primary building block for code generation in macros.
Outside macros it yields the template as an SExpr value — reach for it when
a macro needs to emit brand-new code (rather than just splicing arguments
into existing code).
## Syntax
[macro/quote expr]
`expr` is preserved literally. `$param` references inside it are not
substituted (unlike a plain macro body). `[macro/unquote $param]` is the
escape hatch.
## Behaviour
| Form | `$param` substituted? |
|------|----------------------|
| `[macro/quote ...]` | No — preserved as literal symbol |
| `[macro/quote ... [macro/unquote $x] ...]` | Yes, inside the unquote only |
| `[macro/syntax-quote ...]` | Yes (substituted normally) + bare symbols gensym'd |
| plain macro body | Yes |
The quoted body becomes the macro's expansion and is compiled in place
at the call site.
## Example
defmacro unless {|cond body| [macro/quote [if [macro/unquote $cond] nil [macro/unquote $body]]] } [unless false { echo "ran" }] # expands to: [if false nil { echo "ran" }] # => prints "ran"
Without `macro/quote`, every `$param` in the body would be substituted
directly. `macro/quote` defers that — only `[macro/unquote ...]` escapes
back to substitution, letting you mix literal structure with parameter
values.
## Important: use `[...]`, not `(...)`
Deft's bare `( ... )` parens are infix-only (e.g. `($a + $b)`).
`(macro/unquote $x)` is a syntax error. Always use brackets:
`[macro/unquote $x]`.
## When to reach for macro/quote
- You're building new code from scratch (control structures, DSLs).
- You want a `$param` reference to survive into the expansion as a
literal symbol (resolved against the caller's scope at runtime).
For most macros — where you just splice `$param` into existing code —
direct substitution is enough; no `macro/quote` needed.
## See Also
`macro/syntax-quote`, `macro/unquote`, `macro/splice`, `begin`, `defmacro`