I have this expression ,
(write (cdr (car' ('(p q) r))))
which gives ((P Q)) as the output . I've been scratching my head all day and am still unable to figure out how this works .
Doing just the car part gives,
(write (car' ('(p q) r)))
gives '(P Q) .
Then , according to me (cdr '(P Q)) should give (Q) as the output .
How is the final answer , '(P Q) is my question .
You have an extra quote (the first one is stuck to the
carbut still parses correctly) in there which causes a quoted quote, so what you essentially have is:Taking the
carof this leaves you with just the data:And again taking the
cdrof this results in the data:As you observed. If you look at the car of the car instead with
you should see the
itself. Remember that
'(a b)and(quote (a b))are the same thing, and the printout from whatever you're using might show either form.So what you want to do is just remove the extra quote, i.e.: