Carlos
10/11/2006 4:59:00 PM
Sam Kong wrote:
> Hi,
>
> I'm trying to understand continuation.
> There's some confusion in the following:
>
> In top-level,
>
> [1]
> callcc { |c| $label = c }
> #...some other code here
> $label.call
>
> [2]
> $label = callcc { |c| c }
> #...some other code here
> $label.call
>
>
> Are they same or different?
> As I understand it, callcc returns the last expression or return value
> of c.call.
> Thus, basically [1] and [2] should be same, right?
> But I'm not sure.
> Can anyone explain it, please?
callcc returns the return value of its block, the first time. Later, it
returns the value it was called with.
If you test [2], you'll see the error message:
undefined method `call' for nil:NilClass (NoMethodError)
Try
$label = callcc {|c| c}
$label.call(3)
and
$label = callcc {|c| puts "first call"; c}
$label.call(lambda{puts "second call"})
to understand what's going on.
--