Created
November 7, 2019 22:08
-
-
Save chelseatroy/80fd12e4212c864fa948d47e5019531a to your computer and use it in GitHub Desktop.
Memoize Thunk
This file contains hidden or 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 (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