KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This is from the SICP book that I am sure many of you are familiar with. This is an early example in the book, but I feel an extremely important concept that I am just not able to get my head around yet. Here it is: (define (cons x y) (define (dispatch m) (cond ((= m 0) x) ((= m 1) y) (else (error "Argument not 0 or 1 - CONS" m)))) dispatch) (define (car z) (z 0)) (define (cdr z) (z 1)) So here I understand that car and cdr are being defined within the scope of cons , and I get that they map some argument z to 1 and 0 respectively (argument z being some cons ). But say I call (cons 3 4) ...how are the arguments 3 and 4 evaluated, when we immediately go into this inner-procedure dispatch which takes some argument m that we have not specified yet? And, maybe more importantly, what is the point of returning ' dispatch ? I don't really get that part at all. Any help is appreciated, thanks!
Tags (comma-separated)
Save Edits
Cancel