I still don't understand exactly what the single quotation mark in a pair literal is for. Is there another way to explain it?
Yes. The single quotation mark is actually an abbreviation for another of
Scheme's keywords, quote. Pair literals are a kind of
quote-expression.
A quote-expression consists of a left parenthesis, the keyword
quote, a datum, and a right parenthesis. The datum can be a
numeral, a Boolean literal, or a pair (that is, two data separated by a dot
and enclosed in parentheses), or indeed any kind of direct literal
representation of a Scheme value.
The result of evaluating any quote-expression is the datum it contains. No
attempt is made to evaluate that datum itself; quote is not a
procedure being applied to an operand, but just a way of marking the fact
that what it encloses is to be taken literally as a value in its own right:
Since it's not going to be evaluated, does the datum even have to be a legal expression of Scheme?> (quote 5) 5 > (quote #f) #f > (quote (1 . 2)) (1 . 2)
No, it does not. The syntax rules for data allow lots of things to qualify as data that are not legal expressions in Scheme:
And the single quotation mark is just a shorthand way of writing quote-expressions?> (quote if) if > (quote (let (lambda . let))) (let (lambda . let)) > (quote ()) ()
That's right. The single quotation mark replaces the outermost parentheses
of a quote-expression and the keyword quote. They are
completely interchangeable. Your Scheme interpreter may even substitute
one for the other when echoing data:
> (quote (quote (1 . 2))) '(1 . 2)
Next topic
Previous topic
Table of contents
This document is available on the World Wide Web as
http://www.math.grin.edu/~stone/scheme-web/quote.html