Created
December 3, 2012 23:42
-
-
Save iwillig/4199109 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (cons x y) | |
| (define (dispatch m) | |
| (cond ((eq? m 'car) x) | |
| ((eq? m 'cdr) y) | |
| (else (error "Undefined operation -- ICONS" m)))) | |
| dispatch) | |
| (define (car z) (z 'car)) | |
| (define (cdr z) (z 'cdr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I prefer it without the dispatch part. But it made my day nevertheless!
(define (cons x y) (lambda (f) (f x y)))
(define (car z) (z (lambda (x y) x)))
(define (cdr z) (z (lambda (x y) y)))