[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

callcc Semantics

Bill Atkins

10/18/2004 4:17:00 AM

What is the purpose of the block passed to callc? Is there a reason
that callcc doesn't just return the Continuation object?

Bill


3 Answers

Florian Gross

10/18/2004 5:08:00 AM

0

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
def Continuation.create(*args, &block)
args = [args] if not args.nil? and not args.is_a? Array # 1.6.8 compatibility
cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?}
result ||= args
return *[cc, *result]
end

Mikael Brockman

10/18/2004 10:22:00 AM

0

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.



Eric Hodel

10/19/2004 3:47:00 AM

0

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?

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....

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.

--
Eric Hodel - drbrain@segment7.net - http://se...
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04