[plt-scheme] Re: newbie question

From: donaldtc at yahoo.cn (donaldtc at yahoo.cn)
Date: Wed Feb 25 01:10:41 EST 2009

Thank you all.
I think I've found the answer.
When I use

(define ha (make-running-total))

ha actually is an instance of the procedure

      (lambda ()
        (let ([m n])
          (set! n (+ n 1))
          (list m n)))

and when I call ha

    (let ([n 0])

will not take effect any more.

This is why I cannot use (make-running-total) to call the procedure
but ((make-running-total)).

Am I right?

On Feb 21, 11:26 am, "donal... at yahoo.cn" <donal... at yahoo.cn> wrote:
> With the following program
>
> #lang scheme
> (define make-running-total
>   (lambda ()
>     (let ([n 0])
>       (lambda ()
>         (let ([m n])
>           (set! n (+ n 1))
>           (list m n))))))
> ((make-running-total))
> ((make-running-total))
> (define ha (make-running-total))
> (ha)
> (ha)
>
> why the result is
>
> (0 1)
> (0 1)
> (0 1)
> (1 2)
>
> It seems when I call (ha), the n is a static variable.
> _________________________________________________
>   For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.