Quote on the diagram

Below is an exercise from SICP. I couldn't figure it out myself. Can anyone help me understand?

Enter the following code into the interpreter:

(car ''abracadabra)

      

And it will print 'quote'. Why?

+2


source to share


2 answers


As Gimpf said, "gibberish = (quote abracadabra). You can check this by typing" abracadabra "in the REPL, which will print (quote abracadabra).



+6


source


Because 'abracadabra really is (quote (quote abracadabra)). In the schema, the rule is: evaluate all parts of the s-expression and apply the first part to the rest of the parts.

"car" and "quote" are the symbols below. #car and #quote are the functions they refer to.

If you take

(car (quote (quote abracadabra)))

      

and appreciate the details, you will receive



(#car (quote abracadabra))

      

Then apply the first part (car function) to the second part (two-character list).

quote

      

And you only get the "quote" character.

Just remember to figure out what's going on in the diagram, evaluate the details, and apply the former to the rest. If you rate a quote, you get the stuff inside. The only confusing part is that some primitives (number and strings) evaluate themselves.

0


source