Ticket #1297: debug.scm

File debug.scm, 699 bytes (added by ai-artisan, 8 years ago)

csi -w -s debug.scm

Line 
1;;debug.scm
2
3(require-extension r7rs)
4
5(define r #t)
6
7(define test (lambda ()
8        (if r
9                (begin
10                        (set! r #f)
11                        (define v 123)
12                        (test)
13                        (display v)
14                        (newline)
15                )
16                (begin
17                        (define v 234)
18                )
19        )
20))
21
22(test)
23
24;; output: 234
25
26;; The question is: Each time a procedure or partial block (like "let") is called, a closure should be created. Variables defined inside a closure should have a limited scope inside the closure unless "call/cc" or "call-with-values" is used. In the case above, none of them is used but the variable "v" survives beyond its closure created by "test" the 2nd time.
27
28;; Further more, I found that only when "begin" is used will this bug appear.