从 Section 2.9. Assignment of The Scheme Programming Language 中看到thunk这个概念,
Local state is sometimes useful for caching computed values or allowing a computation to be evaluated lazily , i.e., only once and only on demand. The procedure lazy below accepts a thunk , or zero-argument procedure, as an argument. Thunks are often used to “freeze” computations that must be delayed for some reason, which is exactly what we need to do in this situation. When passed a thunk t , lazy returns a new thunk that, when invoked, returns the value of invoking t . Once computed, the value is saved in a local variable so that the computation need not be performed again. A boolean flag is used to record whether t has been invoked and its value saved.
(define lazy
(lambda (t)
(let ([val #f] [flag #f])
(lambda ()
(if (not flag)
(begin (set! val (t))
(set! flag #t)))
val))))
上面这段描述, 读得一头雾水
The procedure lazy below accepts a *thunk* , or zero-argument procedure,
这里说thunk
等同于 zero-argument procedure,
只要是没哟argument的procedure都是thunk?
维基百科里解释说thunk是在头昏脑涨凌晨2点钟编造的think的过去式.