[plt-scheme] newbie question

From: donaldtc at yahoo.cn (donaldtc at yahoo.cn)
Date: Fri Feb 20 22:26:07 EST 2009

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.


Posted on the users mailing list.