Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created November 7, 2019 22:08
Show Gist options
  • Save chelseatroy/80fd12e4212c864fa948d47e5019531a to your computer and use it in GitHub Desktop.
Save chelseatroy/80fd12e4212c864fa948d47e5019531a to your computer and use it in GitHub Desktop.
Memoize Thunk
(define (force-it obj)
(if (thunk? obj)
(define-in-environment (name thunk-exp) list('evaluated-thunk ((actual-value (thunk-exp obj) (thunk-env obj))))
obj))
...
(define (evaluated-thunk? obj)
(eq? (car obj) 'evaluated-thunk))
(define (thunk-value evaluated-thunk) (cadr evaluated-thunk))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment