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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -