Csaba Henk
3/7/2005 1:12:00 AM
On 2005-03-06, John Carter <john.carter@tait.co.nz> wrote:
> c = callcc { |c| c }
>
> Can anyone elaborate on this history?
>
> Or is there a deeper reason than mere history?
Of course, this blocky form is useful (as it's with blocky forms in ruby
usually).
But I think it should be allowed to have a plain "callcc" which would
be equivalent with today's "callcc { |c| c }".
You can just do
module Kernel
alias call_with_current_continuation callcc
def callcc(*a,&b)
b ||= proc{ |c| c }
call_with_current_continuation(*a,&b)
end
end
Just like with fork, but the other way around:
traditional unix-style fork works like:
if pid = fork
# parent code...
else
# child code...
end
(this is the way we'd like to have with callcc)
and ruby introduced the blocky form
fork { #child code }; #parent goes on...
but the traditional style fork remained valid.
As a sidenote: with cvs ruby you can do the following:
if pid = callcc { |c| fork{c.call} }
# parent
else
# child
end
That is, traditional fork style can be defined in terms of blocky fork,
thanks to callcc. This might come handy if you bump into some fork
wrapper which supports only the blocky form (imagine, eg., some
pty_fork, which doesn't have proper implementation in current ruby).
Csaba
Csaba