car and cdr in Scheme are driving me crazy ...
Posted
by kristian Roger
on Stack Overflow
See other posts from Stack Overflow
or by kristian Roger
Published on 2010-04-30T20:44:38Z
Indexed on
2010/04/30
20:57 UTC
Read the original article
Hit count: 279
Scheme
Hi Im facing a problem with the car
and cdr
functions
for example:
first I defined a list called it x
(define x (a (bc) d ( (ef) g ) ))
so x now is equal to (a (bc) d ( (ef) g ) )
now for example I need to get the g from this list using only car
and cdr
(!! noshortcuts as caddr cddr !!) the correct answer is:
(car(cdr(car(cdr(cdr(cdr x))))))
BUT how ? :-( I work according to the rules (the car
gives the head of list and cdr
gives the tail)
and instead of getting the answer above I keep reaching wrong answers. Can any one help me in understanding this ... give me step or a way to solve it step by step
Thanks in advance. I'm really sick of Scheme.
© Stack Overflow or respective owner