[plt-scheme] newbie question
What would you expect as output?
Every procedure made by make-running-total has its own variable n.
If you want to use all procedures made by make-running-total to accumulate
in the same variable (but this seems not very logical)
You may want to inspect the results when you exchange the lines
> (lambda ()
> (let ([n 0])
But, as said, this seems not logical.
Jos
----- Original Message -----
From: <donaldtc at yahoo.cn>
To: <plt-scheme at list.cs.brown.edu>
Sent: Saturday, February 21, 2009 4:26 AM
Subject: [plt-scheme] newbie question
> 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