Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Question about recursion in scheme
Post Body

Hello! I have a question about how recursion works.

----------------------------------------------------

(define (unzip plist)

(if(null? plist)

'(().())

(cons (cons (caar plist) (car (unzip (cdr plist))))

(cons (cdar plist) (cdr (unzip (cdr plist)))))))

-------

So basically, this code combines the first digit of each pair to the next one, so for example,

(unzip (list (cons 1 4) (cons 2 5) (cons 3 6)))

this would result in ( 1 2 3 (4 5 6))

So my question is, how exactly does the recursion works, so it takes the caar of plist, which would be 1, and then for (car (unzip (cdr plist))), from what I understand, it recurses the program but this time with ((cons 2 5) (cons 3 6)), but if this is the case, wouldnt it be (caar (unzip (cdr plist)))? since the car of ((cons 2 5) (cons 3 6)) is (2 5) while the caar is 2? Thank you and sorry if its a dumb question. Please let me know if my question isn't clear! I don't think I'll ever able to wrap my head around all of this :(

Author
User Disabled
Account Strength
0%
Disabled 5 months ago
Account Age
4 years
Verified Email
No
Verified Flair
No
Total Karma
530
Link Karma
351
Comment Karma
105
Profile updated: 1 day ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago