Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active October 30, 2019 21:12
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 chelseatroy/7b98c34539a124f1664a81e44d20b5f7 to your computer and use it in GitHub Desktop.
Save chelseatroy/7b98c34539a124f1664a81e44d20b5f7 to your computer and use it in GitHub Desktop.
Environments as Objects
; 3.1
(define (make-counter value)
(define (incr x)
(set! value (+ value x))
value)
incr)
(define counter (make-counter 100))
; > (counter 100)
; 200
; > (counter -1)
; 199
; > (counter 10)
; 209
; > (counter -150)
; 59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment