What is the purpose of the block passed to callc? Is there a reason
that callcc doesn't just return the Continuation object?
Bill
What is the purpose of the block passed to callc? Is there a reason
that callcc doesn't just return the Continuation object?
Bill
Bill Atkins wrote:
What is the purpose of the block passed to callc? Is there a reason
that callcc doesn't just return the Continuation object?
Mostly tradition, I think. Plus without the block and no new arguments there would be no way of knowing whether the Continuation was called yet or not.
I've done my own variation (I always felt the interface of callcc was inside out -- yielding instead of returning) which lets you supply arguments on creation and overwrite them on invokation; it then returns the Continuation and those arguments.
I've attached the file with my interface as I think callcc itself won't change much -- maybe this is a help to you anyway.
Regards,
Florian Gross
simplecc.rb (247 Bytes)
Bill Atkins <batkins57@gmail.com> writes:
What is the purpose of the block passed to callc? Is there a reason
that callcc doesn't just return the Continuation object?
The block isn't part of the continuation. Try writing
catch :break do
callcc do |$k|
puts 'hello'
throw :break
end
puts 'world'
end
using only returncc.
This has been discussed at least once in the past, see the ruby-talk
email archives:
http://www.google.com/search?q=site%3Aruby-talk.org+callcc
I will say that call-with-current-continuation cannot work without the
block passed to it. IOW, call (this block of code) with the current
continuation (which gets passed to it as an argument).
x = callcc do |cc| ... end
^^
Here || is the "current continuation" for callcc. Without the block,
you can't return here and not do whatever was done in the block. This
is very important, without it you can't do much truly interesting stuff.
Bill Atkins (batkins57@gmail.com) wrote:
What is the purpose of the block passed to callc? Is there a reason
that callcc doesn't just return the Continuation object?
--
Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04