rascal
rascal copied to clipboard
Strange failure of tests for all
Some tests in ComprehensionsTests.all failed and I cannot understand how they ever succeeded. The offending tests were:
assertTrue(runTest("all(_ <- [])"));
assertTrue(runTest("all(_ <- {})"));
assertTrue(runTest("all(_ <- ())"));
assertTrue(runTest("all(i <- [1,2,3], (i % 2 == 0 || i % 2 == 1))"));
Imho the first three should yield false (this is weird property of all) and the last one now fails.
I have switched the first three to assertFalse and I have commented out the last one.
Any ideas what is going on here?
Yes, I probably accidentally committed these, without fixing all. The first 3 should return true. This is a bug of all. I don't know about the last one.
We should change the syntax of all and one to fix them. Either that or we make generators to always return true, but that would seriously break other things.
How about:
all( i % 3 == 0 | i <- [3,6,9])
On the right of the bar is just comprehension syntax, where the tests are used to filter what is generated. On the left is the boolean yest that has to be true for all iterations.
I don't understand why this isn't merely an implementation issue. all should behave differently from generators in comprehensions/for-loops/if-statements. And it should be dual to any.
because you can not decide whether or not the generator will produce zero
bindings in advance. Consider all(int i <- ["x","y"], i % 2 == 0), which
should return true according to your semantics, yet the list is not empty.
On Tue, Jan 29, 2013 at 10:44 AM, Tijs van der Storm < [email protected]> wrote:
I don't understand why this isn't merely an implementation issue. allshould behave differently from generators in comprehensions/for-loops/if-statements. And it should be dual to any.
— Reply to this email directly or view it on GitHubhttps://github.com/cwi-swat/rascal/issues/118#issuecomment-12827182.
Jurgen Vinju
-
Centrum Wiskunde & Informatica - SEN1
-
INRIA Lille - ATEAMS
-
Universiteit van Amsterdam
www: http://jurgen.vinju.org, http://www.rascal-mpl.nl, http://twitter.com/jurgenvinju skype: jurgen.vinju
@PaulKlint this is our sixtht oldest open issue. Let's squash this.
allandanyshould ready like logical quantifiers "forall" and "exists", there is always:- a selection of collections that bind to some variable; with a cartesian product semantics
- a logical expression that is tested for each of the resulting bindings. with
allthey should all be true withanyat least one.
Syntax alternatives:
all( gen1, gen2, ... | predicate1, predicate2 ...)- before the bar|we generate and possibly filter bindings, and after the bar all of these bindings must be true.- the same but with the predicates swapped with the generators
forall (gen1, gen2, ... ) predicate- .. please add more here..
Questions:
- do we allow filters among the generators?
- do we allow generators among the predicates?
- other programming languages?
Examples:
- Are all numbers even:
all(elem <- lst | elem % 2 == 0)
- Are all even numbers also divisible by 3?
all(i <- [0..100], i % 2 == 0 | i % 3 == 0)