[plt-scheme] begin0 and tail recursion

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sun Jul 20 09:59:37 EDT 2003

It isn't a tail call because it must evaluate E1, then evaluate E2, and
then return E1's result.

Robby

At Sun, 20 Jul 2003 16:58:12 +0000, "Saint Katsmall T. Wise, Esquire" wrote:
> ------------------------------------------------------------------------------
> It doesn't tail call because it evaluates x first, right?
> 
> Robby Findler wrote:
> 
> >  For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> >begin0 doesn't tail call any thing. 
> >
> >(begin0 E1 E2) = (let ([x E1]) (begin E2 x))
> >
> >Robby
> >
> >At Sun, 20 Jul 2003 15:36:34 +0200 (MEST), Stefan Ottosson wrote:
> >  
> >
> >>  For list-related administrative tasks:
> >>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >>
> >>Hi,
> >>
> >>I'm probably being naive, but shouldn't the following code be tail
> >>recursive? It seems it isnt, unless you remove 'pop from the second
> >>last line.
> >>
> >>(define (faki n)
> >>  (define (iter n res)
> >>    (if (= n 0)
> >>        (continuation-mark-set->list
> >>                     (current-continuation-marks) 'key)
> >>        (with-continuation-mark 'key (gensym 'env)
> >>                                (begin0 (iter (- n 1) (* n res)) 'pop))))
> >>  (iter n 1))
> >>
> >>(faki 3) returns (env32208 env32207 env32206) as written above. If I
> >>erase 'pop then (faki 3) returns just (env32211).
> >>
> >>    
> >>
> >
> >
> >  
> >
> 
> ------------------------------------------------------------------------------
> It doesn't tail call because it evaluates x first, right?
> Robby Findler wrote:
> 
>   For list-related administrative tasks:
> 
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> 
> 
> begin0 doesn't tail call any thing. 
> 
> 
> 
> (begin0 E1 E2) = (let ([x E1]) (begin E2 x))
> 
> 
> 
> Robby
> 
> 
> 
> At Sun, 20 Jul 2003 15:36:34 +0200 (MEST), Stefan Ottosson wrote:
> 
>   
> 
>   For list-related administrative tasks:
> 
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> 
> 
> Hi,
> 
> 
> 
> I'm probably being naive, but shouldn't the following code be tail
> 
> recursive? It seems it isnt, unless you remove 'pop from the second
> 
> last line.
> 
> 
> 
> (define (faki n)
> 
>   (define (iter n res)
> 
>     (if (= n 0)
> 
>         (continuation-mark-set->list
> 
>                      (current-continuation-marks) 'key)
> 
>         (with-continuation-mark 'key (gensym 'env)
> 
>                                 (begin0 (iter (- n 1) (* n res)) 'pop))))
> 
>   (iter n 1))
> 
> 
> 
> (faki 3) returns (env32208 env32207 env32206) as written above. If I
> 
> erase 'pop then (faki 3) returns just (env32211).
> 
> 
> 
>     
> 
> 
> 
> 
>   
> 
> ------------------------------------------------------------------------------



Posted on the users mailing list.