Scheme explanation - cdr and car -
i've got example :
(apply + 2 (cdadr '(1 ((2 . 3) 4)))) this returns 6? why (cdadr '(1 ((2 . 3) 4))) 4?? don't it.shouldn't 3?
the result list '(4), not number 4.
you have list 2 elements, 1 first element, , list ((2 . 3) 4) second element.
in other words, cdr of list (cons ((2 . 3) 4)) '()), or (((2 . 3) 4)).
> (cdr '(1 ((2 . 3) 4))) '(((2 . 3) 4)) this list 1 element - list ((2 . 3) 4) - of course car.
> (car (cdr '(1 ((2 . 3) 4)))) '((2 . 3) 4) and, finally,
> (cdr (car (cdr '(1 ((2 . 3) 4))))) '(4)
Comments
Post a Comment