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

Re: CPS != call/cc




   Date: Wed, 6 Aug 2003 13:42:29 -0400
   Subject: Re: CPS != call/cc
   Cc: "Peter J. Wasilko, Esq." <futurist@cloud9.net>, Dan Sugalski 
<dan@sidhe.org>, ll1-discuss@ai.mit.edu
   To: John Clements <clements@brinckerhoff.org>
   From: John Clements <clements@brinckerhoff.org>
   
   
   On Wednesday, August 6, 2003, at 01:10  PM, John Clements wrote:
   
   >
   > On Wednesday, August 6, 2003, at 11:00  AM, Peter J. Wasilko, Esq. 
   > wrote:
   ...
   >
   > EXAMPLE:
   >
   > this program is in CPS (w.r.t. user-defined procedures):
   >
   > (define (fact-cps n k)
   >   (if (= n 0)
   >     (k 1)
   >     (fact-cps (- n 1) (lambda (x) (* x n)))))
   
   ... of course I was going to make a mistake.  Here's the correction:
   
   (define (fact-cps n k)
      (if (= n 0)
        (k 1)
        (fact-cps (- n 1) (lambda (x) (k (* x n))))))

Even more accurate would be:

(define (fact-cps n k)
   (= n 0
      (lambda (b)
        (if b
           (k 1)
           (- n 1
              (lambda (m)
                (fact-cps m (lambda (x) (* x n k)))))))))

That is, we assume that =, -, and * also take continuations.

--Guy