A complete reference for Scheme's four quoting forms — how they work, when to use them, and the classic pitfall with (car '(list ...)) .
| Syntax | Full form | What it does |
|---|---|---|
'x |
(quote x) |
Freezes x entirely — nothing inside is ever evaluated. Returns the raw data structure. |
x ` |
(quasiquote x) |
Like quote, but allows selective evaluation inside via , and ,@. |
,x |
(unquote x) |
Inside a quasiquote: forces evaluation of x and splices the result in. |
,@x |
(unquote-splicing x) |
Inside a quasiquote: evaluates x (must be a list), then inlines all elements. |
' (quote) freezes a structure; ' freezes everything inside — no evaluation happens at any depth
(define x 42)
'x ; => x the symbol x, not 42
'(+ 1 2) ; => (+ 1 2) a three-element list, not 3
'(1 2 3) ; => (1 2 3) a list of numbers — fine
'(list 1 2 3) ; => (list 1 2 3) a four-element list; "list" is just a symbol
📌 Note
Inside a quoted expression, every identifier is a symbol, not a function reference. The names
list,+,car— all become inert symbols when quoted.
(car '(list 1 2 3)); What does this return?
(car '(list 1 2 3)) ; => list ← the SYMBOL "list", not 1 !
; Why? The quote freezes the whole expression.
; The list looks like this internally:
; element 0: the symbol list
; element 1: the number 1
; element 2: the number 2
; element 3: the number 3
; car picks element 0, which is the symbol "list".
; (length '(list 1 2 3)) => 4, not 3 !
📌 Note
Many beginners write
'(list 1 2 3)expecting it to behave like(list 1 2 3). It does not.'preventslistfrom being called — it becomes a plain symbol sitting at the head of a 4-element list.
; Goal: get (1 2 3) and apply car to get 1
; Option A — call the list function (no quote)
(car (list 1 2 3)) ; => 1 ✓
; Option B — quote a literal data list (no function name inside)
(car '(1 2 3)) ; => 1 ✓
; Wrong — don't mix quote with a function call inside
(car '(list 1 2 3)) ; => list ✗
💡 Example
Use
'(1 2 3)when the list contains only literal data (numbers, booleans, symbols you want verbatim). Use(list ...)when any element needs to be computed or when you're calling functions.
(define x 42)
(define lst '(1 2 3))
`(a x b) ; => (a x b) no comma — x is still a symbol
`(a ,x b) ; => (a 42 b) ,x forces evaluation — 42
`(a ,@lst b) ; => (a 1 2 3 b) ,@lst splices the list in
; Mental model: backtick is a template, comma is ${...}
; `(a ,x b) → `a ${x} b` in JavaScript
; `(a ,@lst b) → `a ${...lst} b`
This is the most common real-world use: building code templates in define-syntax or define-macro.