[plt-scheme] begin0 and tail recursion

From: Saint Katsmall T. Wise, Esquire (kela_bit at netvision.net.il)
Date: Sun Jul 20 12:58:12 EDT 2003

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).
>>
>>    
>>
>
>
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20030720/356aaa97/attachment.html>

Posted on the users mailing list.