This chapter in SICP says that the definition of actual-value
for extracting a thunk's real value is this:
(define (actual-value exp env)
(force-it (eval exp env)))
But what if exp
itself is a thunk? Based on the definition of delay-it
it would mean that it is a list object of the form (list 'thunk exp env)
. The eval function however is in no way prepared for handling tagged lists beginning with 'thunk. Why doesn't eval produce an error due to the unmatched cond expression?
Edit: I think evaluating the following expression should result in an error:
(define (add a) (+ 2 a))
(add 0)
add
is a compound procedure, therefore delay-it
is performed on its arguments before it being applied. +
is a primitive produce, which means that actual-value
will be called on its arguments. The arguments are 2 and a. a is a thunk object, therefore actual-value
should produce an error when it passes it to eval
, because eval
does not have a cond case which deals with lists tagged with 'thunk.