Created
November 7, 2019 22:02
-
-
Save chelseatroy/24f760833b03a92f3a676731a493716d to your computer and use it in GitHub Desktop.
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
; "Thunk:" An unevaluated expression along with an environment (where it would evaluate) | |
(define (delay-it sexp env) | |
(list 'thunk sexp env)) | |
(define (thunk? obj) | |
(and (pair? obj) (eq? (car obj) 'thunk))) | |
(define (thunk-exp obj) | |
(cadr obj)) | |
(define (thunk-env obj) | |
(caddr obj)) | |
; Evaluation of thunks | |
(define (force-it obj) | |
(if (thunk? obj) | |
(actual-value (thunk-exp obj) (thunk-env obj)) | |
obj)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment