nice explanation of call/cc

Discussion in 'Ruby' started by Martin DeMello, Feb 12, 2007.

  1. From http://sigfpe.blogspot.com/2007/02/exceptions-disjunctions-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.
     
    Martin DeMello, Feb 12, 2007
    #1
    1. Advertising

  2. Martin DeMello

    Pit Capitain Guest

    Pit Capitain, Feb 12, 2007
    #2
    1. Advertising

  3. 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 <> wrote:
    > Martin DeMello schrieb:
    > >> From http://sigfpe.blogspot.com/2007/02/exceptions-disjunctions-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
     
    Giles Bowkett, Feb 13, 2007
    #3
  4. 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 <> 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 <> wrote:
    > > Martin DeMello schrieb:
    > > >> From http://sigfpe.blogspot.com/2007/02/exceptions-disjunctions-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
    >
    >
     
    Martin DeMello, Feb 13, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hugh G. Johnson

    ASP.NET and SQL 2000 not playing nice?

    Hugh G. Johnson, Sep 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    513
    Hans Kesting
    Sep 7, 2004
  2. =?Utf-8?B?RG90bmV0IFdhbmRlcmVy?=

    I'm Envious of the nice ASP.NET gradient toolbars

    =?Utf-8?B?RG90bmV0IFdhbmRlcmVy?=, Nov 15, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    4,445
    Scott M.
    Nov 15, 2004
  3. SpamProof
    Replies:
    3
    Views:
    650
    SpamProof
    Dec 1, 2003
  4. Torsten Grust
    Replies:
    0
    Views:
    444
    Torsten Grust
    Sep 21, 2006
  5. Chris Bardon

    Is there a nice way to dynamically call a web service?

    Chris Bardon, Apr 29, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    147
    Andrew Hopper
    Apr 29, 2004
Loading...

Share This Page