Next: , Previous: , Up: Quoting   [Contents][Index]


14.4.1 Quoting with quote

The special form quote returns its single argument, as written, without evaluating it. This provides a way to include constant symbols and lists, which are not self-evaluating objects, in a program. (It is not necessary to quote self-evaluating objects such as numbers, strings, and vectors.)

Special Form: quote object

This special form returns object, without evaluating it.

Because quote is used so often in programs, Lisp provides a convenient read syntax for it. An apostrophe character (‘'’) followed by a Lisp object (in read syntax) expands to a list whose first element is quote, and whose second element is the object. Thus, the read syntax 'x is an abbreviation for (quote x).

Here are some examples of expressions that use quote:

(quote (+ 1 2))
     ⇒ (+ 1 2)
(quote foo)
     ⇒ foo
'foo
     ⇒ foo
''foo
     ⇒ (quote foo)
'(quote foo)
     ⇒ (quote foo)
['foo]
     ⇒ [(quote foo)]

Numeric constants, indefinite symbols, string constants, character constants and the special forms t and nil evaluate themselves. Quoting them is allowed but optional. Vector constants created with the bracket notation ([ ]) are also immune against quoting. See Self-Evaluating Forms.

'12
  ⇒ 12
'2.333
  ⇒ 2.333
'1/2
  ⇒ 1/2
'2+5Z
  ⇒ 2+5Z
'Z/12Z
  ⇒ Z/12Z
'1+2i
  ⇒ 1+2i
'0.5-0.5i
  ⇒ 0.50000-0.50000i
'+infinity
  ⇒ +infinity
'-infinity
  ⇒ -infinity
'complex-infinity
  ⇒ complex-infinity
'not-a-number
  ⇒ not-a-number
'"string"
  ⇒ "string"
(eval ''#r"\a\b\c")
  ⇒ "\\a\\b\\c"
'?a
  ⇒ ?a
'?'
  ⇒ ?\'
't
  ⇒ t
'nil
  ⇒ nil
[a b c]
  ⇒ [a b c]
'[a b c]
  ⇒ [a b c]

Next: , Previous: , Up: Quoting   [Contents][Index]