When the result of a computation depends on a changing context, it is often sensible to delay computation of a result until the last possible instant, so as to produce a result as up-to-date as possible.
If the code using the value is not aware that it is runtime computed, however, this can often be difficult to arrange, and can result in a maze of twisty little functions once it has been arranged.
Muq MUF's answer to this design problem is the thunk: A chunk of code which may be freely copied around and stored in variables, properties and so forth, but which will be transparently evaluated and replaced by its result as soon as any computation depending on its value is attempted(6).
Thunks have the same syntax as anonymous functions, except
that the double colon is replaced by star-colon
:
Stack: *: 2 3 + ; Stack: <thunk> 1+ Stack: 6
Implementation of thunks presents some interesting security problems ... grin.
Go to the first, previous, next, last section, table of contents.