While studying cons
, cdr
and car
to handle lists I tried following :
(cadr '('(1) '(2)))
'(2)
which gives the second item in the list as expected. Whereas following gives :
(cdadr '('(1) '(2)))
((2))
How is data being concerted to code and still not giving error?
How was this evaluated?
cdr on '(2) should give nil, which is does. Why not above?
[I am new to both clisp and stackoverflow so pardon me.]
quote
is a special operator which returns its single unevaluated argument. The form (quote ...)
can be abbreviated using '
as '...
. Since the '
is handled by the reader, the form
'('(1) '(2)))
is actually read the same as
(quote ((quote (1)) (quote (2)))
The outermost application quote
to the the argument((quote (1)) (quote (2)))
returns that argument. The cadr
of that argument is the list
(quote (2))
whose first element is the symbol quote
, and whose second element is a list of a single element 2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With