thinking of thunks
how do we delay evaluation?
- with a lambda! just like our implementation of streams
- from argument expression e, create a procedure
(lambda () (meval e env))
- which, when applied, evaluates e in its lexical environment
- this value is called a thunk
how do we keep track of thunks?
- tag each thunk by making a list whose car is the symbol ‘thunk
- when using any value, force it first:
for a value v that is not a thunk, (force v) is v
for a value v that is a thunk, (force v) is (v)
problem set code
- look at procedures delay-it and force-it
- check that you understand how they work
- environment is bound slightly differently:
first form a procedure value (lambda (env) (meval e env))
then form thunk (lambda () (proc env)) where proc is the procedure value