-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect behavior of || in list comprehension #1469
Comments
Thanks for the report Bastiaan; we need to either clarify or fix this. @PaulKlint interesting to see what the compiler makes of this right now. |
to comment and separate some issues:
So here we see that the operational semantics of backtracking over boolean expression operands interferes with the natural semantics of the boolean expression. Either we make completely predictable how often I suspect that fixing this in the interpreter is really complex, while the compiler may have enough static analysis capabilities to "do this right".. |
One explanatory one-liner would be: a comprehension condition is a generator of bindings, and that the comprehension semantics should iterate over all distinguishable bindings at least once, and also maximally once. Bastiaan reports that this is not true because Another simple explanatory one-liner would be that: "the comprehension iterates as many times as the algorithm backtracks". This would make the current bug a "feature". But, I find it quite unsatisfactory that such an algorithmic detail seeps into the formal semantics of the Rascal language. Also this would prohibit different implementation strategies that skip or optimize false valuations (for example by short-circuiting the The previous one-liner which focuses on unique bindings (including the empty environment) allows for many different implementation strategies which can be compared on efficiency, but would all result in the same amount of elements in the list comprehension. |
Operator || behaves incorrectly in a list comprehension (probably caused by the operator's backtracking behavior).
rascal>[ x | x <- [0..10], true || true ]
list[int]: [0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9]
This result is incorrect: true || true should ALWAYS be semantically equivalent to true (i.e. give the same result).
Suggested fix if backtracking semantics turns out to be (too) complex: let && and || be the standard (boolean) operators, and introduce new operators (&&& and ||| come to mind) for the more experimental features.
The text was updated successfully, but these errors were encountered: