A strategydef in a let does not have global scope for its variable bindings, but there’s a leak in there.

Example:
————————–
module let-varscope
imports lib
strategies
main =
let s = ?n; debug(!"n: ")
; inc => n’; debug(!"n’: ")
; !(, n’)
in <map(s)> [1, 2, 3, 4, 5, 6]
end
—————————

Compiling and running gives:
[adam@madras:misc]$ ./let-varscope
n: 1
n’: 2
n: 2
./let-varscope: rewriting failed

Not that the program correctly fails on the second rebinding of n’, but it should have failed one step earlier upon rebinding n. Seemingly n has gotten local scope automagically.

If I change the !(, n’) to !(n, n’), running the program fails as expected:

[adam@madras:misc]$ ./let-varscope
n: 1
n’: 2
./let-varscope: rewriting failed

I presume in the original example, the ?n is removed during compiler-optimization, since it’s not used anywhere, and thus does not cause rebinding failures.
So maybe not a real bug, but it’s a bit strange.

Submitted on 11 May 2004 at 09:14

On 28 July 2005 at 15:42 Jira commented:

STR-85, visser:
Added test; this has been fixed in the Stratego-Core refactoring.

Log in to post comments