car and cdr in scheme is 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:47 UTC
Read the original article Hit count: 288

Filed under:

Hi Im facing a probem with the car and cdr functions

for example:

first I defined a list caled 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 rule (the car gives the head of list and cdr gives the tail)

and instead of getting the answer above I keep reaching wronge answers can any one help me in understanding this ... give me step or a way to solve it step by step

thanx in advance Im really sick of scheme language.

© Stack Overflow or respective owner

Related posts about Scheme