4.10 Quoting: quote and ’
Literals: quote and #%datum in Reference: Racket also documents quote.
The quote form produces a constant:
(quote datum)
The syntax of a datum is technically specified as anything that the read function parses as a single element. The value of the quote form is the same value that read would produce given datum.
The datum can be a symbol, a boolean, a number, a (character or byte) string, a character, a keyword, an empty list, a pair (or list) containing more such values, a vector containing more such values, a hash table containing more such values, or a box containing another such value.
Examples: | ||||||||||||||
|
As the last example above shows, the datum does not have to match the normalized printed form of a value. A datum cannot be a printed representation that starts with #<, so it cannot be #<void>, #<undefined>, or a procedure.
The quote form is rarely used for a datum that is a boolean, number, or string by itself, since the printed forms of those values can already be used as constants. The quote form is more typically used for symbols and lists, which have other meanings (identifiers, function calls, etc.) when not quoted.
An expression
'datum
is a shorthand for
(quote datum)
and this shorthand is almost always used instead of quote. The shorthand applies even within the datum, so it can produce a list containing quote.
Reading Quotes in Reference: Racket provides more on the ’ shorthand.
Examples: | ||||||||
|