hankache / rakuguide

The Raku Guide

Home Page:https://raku.guide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`0 ^.. 10` is NOT the same as `1 .. 10`

raiph opened this issue · comments

commented

I'm raising this issue rather than a PR because it's not obvious if anything needs to be done. But...

This twitter thread caught my attention. It seems that perl6intro implies that 0 ^.. 10 and 1 .. 10 are the same. But...

say (0 ^.. 10) eqv (0 ^.. 10); # True
say (0 ^.. 10) eqv (1 .. 10);  # False

0 ^.. 10 is a range that starts above zero (and stops at 10). 1 .. 10 starts at 1 (and stops at 10).

These two ranges, used when an integer range is expected, produce the same result. But, when used in other scenarios, they may not:

say 1e-999999 ~~ 0  .. 10; # True
say 1e-999999 ~~ 0 ^.. 10; # False
say 1e-9      ~~ 0  .. 10; # True
say 1e-9      ~~ 0 ^.. 10; # True
say 1.0       ~~ 1 ^.. 10; # False
say 1.1       ~~ 1  .. 10; # True

See the Range doc for more details.