It is possible to make annotations that visually look identical but still do not match:

stratego> !(1 {2}, 1 {2}); debug; equal // (basic case; works fine)
(1{2},1{2})
(1{2},1{2})
stratego> !(1 {2}, 1 {^2}); debug; equal
(1{2},1{2})
command failed
stratego> a* := 2; !(1 {2}, 1 {^[a*]}); debug; equal
(1{2},1{2})
command failed
stratego> { !1 {^2}; ?1 {a*} }
command failed

Although it seems intuitively wrong to use this kind of annotation construction for non-list annotations, Dryad did this, and STRC accepts it without complaints. Visual inspection even seems to acknowledge that it works. Perhaps some sort of runtime “is-list” check should be introduced?

Submitted on 12 March 2007 at 10:16

On 12 March 2007 at 16:19 Jira commented:

STR-706, martin:
Or as a Stratego module (not suitable as a testsuite yet)


module foo
imports libstratego-lib
strategies

main =
basic
; test1
; test2
; test3

basic =
!(1 {2}, 1 {2})
; maybe-equal

test1 =
!(1 {2}, 1 {^2})
; maybe-equal

test2 =
a* := 2
; !(1{2}, 1 {^[a*]})
; maybe-equal

test3 =
!1 {^2}
; ?1 {a*}
; !a*
; debug(!"a* is bound to ")

strategies

maybe-equal =
where( (stderr(), ["equal? ", , " "]))
; if equal then say(!“yes”) else say(!“no”) end
——————————————–

Current behaviour:
——————————————–
martin@linux:~> ./foo
equal? (1{2},1{2}) yes
equal? (1{2},1{2}) no
equal? (1{2},1{2}) no
a* is bound to 2
2
——————————————–

Indeed, non-lists should not be allowed after the ^ . For static terms the compiler itself can give an error, for terms including variables, there should be a runtime check.


On 28 January 2013 at 14:46 Eelco Visser removed tag 0.18M2

On 28 January 2013 at 14:46 Eelco Visser tagged interesting

Log in to post comments