[plt-scheme] begin0 and tail recursion

From: Stefan Ottosson (sot at lysator.liu.se)
Date: Sun Jul 20 09:36:34 EDT 2003


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)
                     (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.