[plt-scheme] Stylistic (I hope!) question regarding driver loop

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sat Jan 21 15:46:12 EST 2006

Robby Findler wrote:
> The body of a letrec is in tail-position wrt to the letrec, so you're
> set on that score.
> (FWIW, You can test this out yourself. This program:
>   (define (f x) (letrec ([x x]) (f 1)))
>   (f 1)
> doesn't accumulate memory, but this one (for example):
>   (define (f x) (letrec ([x (f 1)]) x))
>   (f 1)
> does. Watch out in the second case -- it allocates memory pretty
> quickly and gets hard to break pretty quickly too.)

Greg, try using syntax-check on this program in DrScheme:

(define (f x) (letrec ([x x]) (f 1)))
   (f 1)

(define (g x) (letrec ([x (g 1)]) x))
   (g 1)

Then notice the purple arrow, when you
move the arrow over f.

Then try the same with g.

Jens Axel Søgaard

Posted on the users mailing list.