[racket] The function that returns closure and symbols leaking

From: Kazimir Majorinc (kazimir at chem.pmf.hr)
Date: Sat May 14 22:55:47 EDT 2011

I want to write the function "counted" that generates closures in
Scheme; I want that after this

    (define f (counted '(x) '(+ x x)))

f behaves like I wrote

   (define f (let((i 0))
               (lambda(x)            ;first argument
                 (set! i (+ i 1))
                 (display i)
                 (+ x x))))          ;second argument

and to avoid symbols leaking which happens if I call

    (define f (counted '(i) '(+ i i)))

How would you do that "idiomatically"?

Is it possible to avoid symbol leaking relying only on lexical scope, 
without explicit alpha-conversion (gensym, built in or manual) and 
without macros?

Thanks
Kazimir Majorinc







Posted on the users mailing list.