So I am dealing with continuations and have something like this:
(or
(call/cc (lambda (cont)
...
(if ( ... )
(cons randomList (lambda() (cont #f)))
#f)})}
( do something else)
I was wondering what the difference between (lambda() (cont #f)) and (cont #f) are. I get the answer I want with the lambda and something wrong without. Could someone explain the difference? Thanks.
A nullary (zero arguments) lambda used in this way is called a thunk.
Thunks are used in Scheme to defer the execution of some piece of code. Suppose, for example, that we're talking about (display #f)
instead of (cont #f)
. If you wrote (display #f)
directly, then when the code execution reached that point, it'd display #f
straight away, whereas if you wrapped it in a thunk ((lambda () (display #f))
), it wouldn't display the #f
until you invoked the thunk.
Back to your code, a (cont #f)
in the code would cause an immediate jump at the point where the continuation is invoked. Wrapping it in a thunk delays the invocation of the continuation until you invoke the thunk.