Scoping bug in Racket v5.1.1?
Somebody please tell me this is a bug in Racket (v5.1.1),
It seams to be a scoping problem.
(see code and output below)
The return from example-1 shows that x is not getting incremented as it should and as it does in example-2 and example-3.
The function example-2 is just a copy of example-1 with the reverse instruction removed from doit.
The function example-3 (as you can see) is a copy as well but has an additional parameter which by itself does not change anything but when I test it's value in the cond statement it shows x as being incremented.
In addition if I don't return anything from example-1 but rather print what it now returns it shows x as being incremented.
(define (example-1 lst)
(letrec([x 0]
[doit (lambda ()
(reverse
(foldl
(lambda (v store)
(set! x (add1 x))
(cons v store))
'()
lst)))])
(let*([results (doit)])
(list x results)
)))
(define (example-2 lst)
(letrec([x 0]
[doit (lambda ()
(foldl
(lambda (v store)
(set! x (add1 x))
(cons v store))
'()
lst))])
(let*([res开发者_如何学JAVAults (doit)])
(list x results))))
(define (example-3 lst id)
(letrec([x 0]
[doit (lambda ()
(reverse
(foldl
(lambda (v store)
(set! x (add1 x))
(cons v store))
'()
lst)))])
(let*([results (doit)])
(cond [(= 1 id) 'junk])
(list x results)
)))
(printf "example-1 : ~a~n" (example-1 '(a b c)))
(printf "example-2 : ~a~n" (example-2 '(a b c)))
(printf "example-3 : ~a~n" (example-3 '(a b c) 1))
output:
example-1 : (0 (a b c))
example-2 : (3 (c b a))
example-3 : (3 (a b c))
It's a bug -- I filed it with a simpler version of your code. (It's unrelated to the jit though.)
Edit: the bug is fixed now.
精彩评论