Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created November 7, 2019 22:02
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/24f760833b03a92f3a676731a493716d to your computer and use it in GitHub Desktop.
Save chelseatroy/24f760833b03a92f3a676731a493716d to your computer and use it in GitHub Desktop.
Thunk
; "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