Skip to main content

quote

quote Special Operator

Syntax:

quote object → object

Arguments and Values:

object—an object; not evaluated.

Description:

The quote special operator just returns object.

The consequences are undefined if literal objects (including quoted objects) are destructively modified.

Examples:

(setq a 1) → 1
(quote (setq a 3)) → (SETQ A 3)
a → 1
’a → A
”a → (QUOTE A)
”’a → (QUOTE (QUOTE A))
(setq a 43) → 43
(list a (cons a 3)) → (43 (43 . 3))
(list (quote a) (quote (cons a 3))) → (A (CONS A 3))
1 → 1
’1 → 1
"foo" → "foo"
’"foo" → "foo"
(car ’(a b)) → A
’(car ’(a b)) → (CAR (QUOTE (A B)))
#(car ’(a b)) → #(CAR (QUOTE (A B)))
’#(car ’(a b)) → #(CAR (QUOTE (A B)))

See Also:

Section 3.1 (Evaluation), Section 2.4.3 (Single-Quote), Section 3.2.1 (Compiler Terminology)

Notes:

The textual notation ’object is equivalent to (quote object); see Section 3.2.1 (Compiler Terminology).

Some objects, called self-evaluating objects, do not require quotation by quote. However, symbols and lists are used to represent parts of programs, and so would not be useable as constant data in a program without quote. Since quote suppresses the evaluation of these objects, they become data rather than program.

Expanded Reference: quote​

Basic Usage​

quote returns its argument without evaluating it. The reader shorthand ' is equivalent to (quote ...).

(quote hello)
=> HELLO

'hello
=> HELLO

(quote (1 2 3))
=> (1 2 3)

Preventing Evaluation​

Without quote, a symbol would be looked up as a variable and a list would be treated as a function call. quote prevents this.

(setq a 42)
=> 42

a
=> 42

'a
=> A

(list 'a 'b 'c)
=> (A B C)

Self-Evaluating Objects​

Numbers, strings, and characters are self-evaluating -- quoting them is permitted but unnecessary.

42
=> 42

'42
=> 42

"hello"
=> "hello"

'"hello"
=> "hello"

Nested quote​

''a
=> (QUOTE A)

'''a
=> (QUOTE (QUOTE A))

Important: Do Not Modify Quoted Objects​

The consequences are undefined if you destructively modify a quoted literal.

;; BAD -- do not do this:
;; (let ((x '(a b c)))
;; (setf (car x) 'z)) ; undefined consequences