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.
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 :(
Subreddit
Post Details
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnprogra...