Commits

Jürgen Bömmels committed b27460b

Added a closure test

Comments (0)

Files changed (1)

scheme/test/test_scheme_level.py

 (assert (string? new-str))
 (assert (equal? new-str "*******"))
 """)
+
+def test_closures():
+    run_with_assert(r"""
+(define (make-counter start) (lambda () (set! start (+ 1 start)) start))
+(assert (procedure? make-counter))
+(define counter-a (make-counter 10))
+(define counter-b (make-counter 10))
+(assert (procedure? counter-a))
+(assert (eqv? (counter-a) 11))
+(assert (eqv? (counter-a) 12))
+(assert (eqv? (counter-a) 13))
+(assert (eqv? (counter-b) 11))
+""")
+