Skip to content

Instantly share code, notes, and snippets.

@mikeauclair
Created January 18, 2014 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeauclair/8495341 to your computer and use it in GitHub Desktop.
Save mikeauclair/8495341 to your computer and use it in GitHub Desktop.
Closures are poor man's objects. Objects are poor man's closures.
(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