6

I am having some trouble with .one junction and range match:

> say (3,5).any ~~ (1 .. 9)
any(True, True)
> say so (3,5).any ~~ (1 .. 9)
True
> say so (3,5).one ~~ (1 .. 9)
False
> say so (3,0).one ~~ (1 .. 9)  # expect True because 0 not in range and 3 is
False
> say so (3,0).any ~~ (1 .. 9)
True
> say so (0, 3).one ~~ (1..9)   # expected True; 0 not in range; exactly one item (3) is in range
False
> so 0 ~~ 1..9                  # as expected;
False
> so 3 ~~ 1..9
True
> say (0, 3).one ~~ (1..9)      # unexpected; 0 not in range;
one(True, True)                 # expected one(False, True)
> say (1..9).elems
9
> say (0, 10).one ~~ (1..9)     # why is it true that 0 ~~ 1..9 ??
one(True, False)
> say so (0, 10).one ~~ (1..9)  # unexpected !!! neither 0 nor 10 in range
True
> say (-1, 3).one ~~ (1..9)     # why -1 in range of 1..9 ??
one(True, True)
> 

What am I missing? I am using Rakudo Star 2018.10 on MoarVM, implementing Perl6.c.

halfer
  • 19,824
  • 17
  • 99
  • 186
lisprogtor
  • 5,677
  • 11
  • 17
  • Also, say 100000 ~~ 1..(* - 11) will turn \*-11 into 100000-11, and the result is 1..99989, and say so 100000 ~~ 1..(\* - 11) is True; however, 100000 is NOT in the range 1..99989 . ??? – lisprogtor Feb 06 '19 at 21:19
  • Do you mean to do (0,3).any ~~ (1..9).one ? – ugexe Feb 06 '19 at 21:28
  • No, I want to do ( (0,3).one ~~ (1..9) ); I want exactly one item in the list to match the range. Thanks. – lisprogtor Feb 06 '19 at 23:44
  • It looks to me like all the junctions (`one & any & all & none`) have (bizarre) problems with `ACCEPTS` (the method behind `~~`) on a range in 2018.12. I've posted [examples in the issue @lisprogtor started](https://github.com/rakudo/rakudo/issues/2676#issuecomment-461457703). – raiph Feb 08 '19 at 12:46
  • Thank you very much raiph !!! Hopefully this issue will be fixed in the next release !!! – lisprogtor Feb 09 '19 at 08:45
  • @lisprogtor It's ultra surprising that no one has reported it before (which makes me wonder if it's a regression). Lizmat's comments in the issue I linked and related ones suggest it's monumental mental elemental [emmental](https://perl6.party/post/Perl6-On-Specs-Versioning-Changes-And-Breakage). In other words, it seems like a big, crazy, basic, hole in our test coverage. I'm not sure what to make of it but it doesn't sound like fixing it properly will be easy. – raiph Feb 12 '19 at 18:03
  • Hi raiph, I think it is human nature. Sometimes we miss the most obvious. That is the reason a hobbit said: "The nearer we are to danger, the further we are from harm." Meaning that the orcs would not expect to see them :-) – lisprogtor Feb 14 '19 at 09:09

1 Answers1

3

I think the underlying problem is this:

$ perl6 -e 'dd (0,3).one ~~ (1 .. 9)'
one(Bool::True, Bool::True)

That should be one(Bool::False, Bool::True). I think this is a bug, worthy of making an issue for.

Elizabeth Mattijsen
  • 25,654
  • 3
  • 75
  • 105