Skip to content

Instantly share code, notes, and snippets.

@iwillig
Created December 3, 2012 23:42
Show Gist options
  • Select an option

  • Save iwillig/4199109 to your computer and use it in GitHub Desktop.

Select an option

Save iwillig/4199109 to your computer and use it in GitHub Desktop.
(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))
@rmarianski

Copy link
Copy Markdown

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)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment