SICP Exercise 2.55 double-quote
Exercise 2.55. Eva Lu Ator types to the interpreter the expression
(car ''abracadabra)
To her surprise, the interpreter prints back quote. Explain.
SOLUTION
The code and tests are here.
''abracadabra
is actually
'(quote abracadabra)
is actually
(quote (quote abracadabra))
This evaluates to a list of two elements, the first one being a single-quote and the second one being the literal "abracadabra". So 'car' of this will evaluate to quote. Naturally, 'cdr' of the same thing will evaluate to the single element list that contains the literal abracadabra.
(car ''abracadabra)
To her surprise, the interpreter prints back quote. Explain.
SOLUTION
The code and tests are here.
is actually
'(quote abracadabra)
is actually
(quote (quote abracadabra))
This evaluates to a list of two elements, the first one being a single-quote and the second one being the literal "abracadabra". So 'car' of this will evaluate to quote. Naturally, 'cdr' of the same thing will evaluate to the single element list that contains the literal abracadabra.
Comments
Post a Comment