The syntax for list
seems mysterious
'(1 2) and (list 1 2) are the same:
> (equal? '(1 2) (list 1 2))
#t
BUT these are not the same???
(equal? '('(1 2)) (list (list 1 2)))
#f
also
> (list (list 1 2))
'((1 2))
> '( '(1 2))
'('(1 2))
The syntax for list
seems mysterious
'(1 2) and (list 1 2) are the same:
> (equal? '(1 2) (list 1 2))
#t
BUT these are not the same???
(equal? '('(1 2)) (list (list 1 2)))
#f
also
> (list (list 1 2))
'((1 2))
> '( '(1 2))
'('(1 2))
Yep, those are different. The answer here is that quote is much more powerful than you think it is.
Specifically, quote puts you into a "data language"; in this data language, every pair of parentheses introduces a nested list, and every identifier is treated as a symbol.
So, for instance,
'(a (b c) d "e" ((g)))
is the same as
(list 'a (list 'b 'c) 'd "e" (list (list 'g)))
Note how much shorter the first one is, than the second.
When you put a quoted term inside of a quoted term, you're going to get surprises; this is because 't is actually a shorthand for (quote t). So '('(1 2)) is short for (quote ((quote (1 2)))), which is the same as (list (list 'quote (list 1 2))).
Short version: don't put quote inside of quote, and remember that quote enters a "data language". Things get even more interesting with quasiquote!