Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > nice explanation of call/cc

Reply
Thread Tools

nice explanation of call/cc

 
 
Martin DeMello
Guest
Posts: n/a
 
      02-12-2007
From http://sigfpe.blogspot.com/2007/02/e...ions-and.html:

In functional languages exceptions tend to be handled a little
differently. Whereas C++ has a throw keyword, there is no equivalent
in Scheme, say. Instead
the call-with-current-continuation function acts like catch. The
argument to call-with-current-continuation is a function (lambda
(throw) ...) and the argument to this function (itself a function),
here called throw, does the throwing. For example consider the scheme
expression:


(call-with-current-continuation
(lambda (throw) (+ 1 (throw 7))))

[ a = callcc {|c| c[7] + 1} in ruby - martin ]

The result is 7, not 8. The 7 is thrown 'past' the (+ 1 ...) and is
caught by the surrounding call-with-current-continuation. The
important difference from C++ is that if any subexpression is to throw
some value, it must be 'handed' a suitable throw function.

 
Reply With Quote
 
 
 
 
Pit Capitain
Guest
Posts: n/a
 
      02-12-2007
Martin DeMello schrieb:
>> From http://sigfpe.blogspot.com/2007/02/e...ions-and.html:


Martin, thanks for the link. Its nice that we (still) can easily
implement both versions of the code in Ruby, using catch/throw and
continuations.

Regards,
Pit

 
Reply With Quote
 
 
 
 
Giles Bowkett
Guest
Posts: n/a
 
      02-13-2007
I picked up a book on Scheme and seeing call/cc there very much
surprised me. I had seen it Ruby before, I guess it came directly from
Scheme. Anyway there's a neat chapter in that book on
continuation-passing style, which was much different than I expected
it to be. Unfortunately I just relocated and the book's packed in a
box, but the basic idea revolved around that aspect of call/cc. It
didn't actually seem that different from the sequences of methods with
dots style that allows you to feed the output of one method into the
next method, but the syntax was very different (and probably there
were some significant differences to the internals as well).

On 2/12/07, Pit Capitain <(E-Mail Removed)> wrote:
> Martin DeMello schrieb:
> >> From http://sigfpe.blogspot.com/2007/02/e...ions-and.html:

>
> Martin, thanks for the link. Its nice that we (still) can easily
> implement both versions of the code in Ruby, using catch/throw and
> continuations.
>
> Regards,
> Pit
>
>



--
Giles Bowkett
http://www.gilesgoatboy.org
http://gilesbowkett.blogspot.com
http://gilesgoatboy.blogspot.com

 
Reply With Quote
 
Martin DeMello
Guest
Posts: n/a
 
      02-13-2007
Continuation passing style is actually most used as a compilation
stage in several functional languages - the program is first
transformed to cps and that is then used to generate executable code.
I don't think I've seen any language encourage it as an actual coding
style. I agree, it's a very interesting approach, and well worth
reading up on.

martin

On 2/13/07, Giles Bowkett <(E-Mail Removed)> wrote:
> I picked up a book on Scheme and seeing call/cc there very much
> surprised me. I had seen it Ruby before, I guess it came directly from
> Scheme. Anyway there's a neat chapter in that book on
> continuation-passing style, which was much different than I expected
> it to be. Unfortunately I just relocated and the book's packed in a
> box, but the basic idea revolved around that aspect of call/cc. It
> didn't actually seem that different from the sequences of methods with
> dots style that allows you to feed the output of one method into the
> next method, but the syntax was very different (and probably there
> were some significant differences to the internals as well).
>
> On 2/12/07, Pit Capitain <(E-Mail Removed)> wrote:
> > Martin DeMello schrieb:
> > >> From http://sigfpe.blogspot.com/2007/02/e...ions-and.html:

> >
> > Martin, thanks for the link. Its nice that we (still) can easily
> > implement both versions of the code in Ruby, using catch/throw and
> > continuations.
> >
> > Regards,
> > Pit
> >
> >

>
>
> --
> Giles Bowkett
> http://www.gilesgoatboy.org
> http://gilesbowkett.blogspot.com
> http://gilesgoatboy.blogspot.com
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Explanation to Networking Wirelessly?? Jaxim Wireless Networking 4 08-19-2005 05:04 AM
explanation Mariusz VHDL 1 01-13-2004 02:10 AM
Debug message explanation Dean Cisco 1 01-07-2004 12:38 PM
DVMRP Explanation Acer0001 Cisco 0 11-20-2003 04:41 AM
Need Explanation Kaladhaur Palaniappa Perl 0 08-07-2003 09:47 AM



Advertisments