While writing a function in Racket I accidently put two single quotes in front of a symbol instead of one. i.e. I accidently wrote ''a and discovered some behaviour of nested quotes that seems strange. I'm using DrRacket and tested this with both the Racket lang and the R5RS lang.
(write (pair? (quote (quote a))))
prints: #t .
(write (car (quote (quote a))))
prints: quote
But
(write (quote (quote a)))
and
(write '(quote a)))
Both print: 'a
Can someone tell me why in Scheme (and Racket) the function pair? interprets (quote (quote a))) as a pair of two elements quote and a , but the function write prints out 'a instead of (quote a) .
Putting a quote mark (
') around a term and wrapping aquoteform around it are identical. That is, theyreadto the same term.So all of the following expressions are identical in Scheme:
The
quoteform means "interpret what comes next as a datum---even if it contains anotherquote". The sub-term is parenthesized, so it's a list; the innerquoteis just a symbol.In some cases, the printer uses reader-abbreviations like the quote mark (
') in its output. I'm a little surprised that you gotwriteto do it, though; for me, it always writes as(quote a).