Created
January 18, 2014 19:54
-
-
Save mikeauclair/8495341 to your computer and use it in GitHub Desktop.
Closures are poor man's objects.
Objects are poor man's closures.
This file contains 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 person (lambda (first last) | |
(define setFirst (lambda (value) (set! first (list-ref value 0)))) | |
(define setLast (lambda (value) (set! last (list-ref value 0)))) | |
(lambda (method . args) | |
(case method | |
('first | |
(if (null? args) | |
first | |
(setFirst args) | |
) | |
) | |
('last | |
(if (null? args) | |
last | |
(setLast args) | |
) | |
) | |
) | |
) | |
)) | |
(define jimmy (person "Jimmy" "Jams")) | |
(display (jimmy 'first)) | |
(jimmy 'first "Bibble") | |
(display (jimmy 'first)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment