[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A plea for a new old language

> Date: Wed, 7 May 2003 17:33:18 -0400
> From: Dan Sugalski <dan@sidhe.org>
> At 4:32 PM -0400 5/7/03, Shriram Krishnamurthi wrote:
> >There's a confusion in this discussion that Michael Vanier has
> >(inadvertently?) highlighted.
> >
> >My understanding was that Dan Sugalski was planning to use CPS in the
> >*implementation* of Parrot.
> Yes.
> >I was questioning why Dan would need to use CPS in implementing
> >Parrot, or at any rate what that has to do with continuations in
> >source languages.  That question still stands.
> I want to use CPS in the implementation of parrot as I find that, 
> conceptually at least, it solves a lot of messy problems for me. Or, 
> rather, avoids a lot of required messy code emission form compilers.

OK.  Just out of curiosity: do you want to use CPS from within C code?  Or
within parrot code?  I'm pretty sure that you can't use CPS in C, since C
lacks first class functions and tail calls.

> I want continuations in *source* languages because I want a pool of 
> developers comfortable with continuations. Making a required feature 
> of parrot something that people are profoundly uncomfortable with 
> isn't a good way to enlarge that pool.

When you say "required feature", do you mean required for anyone who wants
to hack on the guts of Parrot?  At the C level or at the Parrot level?

> So, simply:
> 1) I want to use CPS
> 2) To use CPS, I need developers who are OK with continuations
> 3) To get developers OK with continuations, they need experience with 
> continuations
> 4) To get them experience with continuations, they need to use a 
> language that they're comfortable with that also has continuations
> 5) Thus, I'd like a *reasonably popular* language in the common style 
> (procedural and/or OO, like it or not) to get continuations added
> Whether or not you *always* need continuations to have an 
> implementation that uses CPS is irrelevant, as you at least 
> *sometimes* need them, and thus familiarity with them is necessary.
> -- 
>                                          Dan

You *never* need first-class continuations a la call/cc to use CPS.  You
just need tail calls and first-class functions.  Consider this example:

;; factorial in continuation-passing style, in scheme:

(define (fact-k n cont)
  (if (= n 0)
      (cont 1)
      (fact-k (- n 1) (lambda (k) (cont (* k n))))))
(define (id n) n)
(define (factorial n) (fact-k n id))

No call/cc here at all.  The continuation is represented explicitly.  You
are right in suggesting that it would be useful if developers who are going
to interact with code that uses CPS should not be scared of code like
this.  However, you don't have to know how to play with call/cc and its
associated peculiarities in order to understand this code.

In summary: familiarity with any language that supports first-class
functions and tail calls, along with some experience writing and reading
functions in CPS, is all they would need.  BTW all functions can be
mechanically converted to CPS, although the result is often not pretty.