perl6 -e '100 ~~ ^100'
returns False
, where it looks like to me it should return True
, as 100 is in the range between 0 and 100. Is this a part of the design of the Range
class that I'm just not understanding here or is this a bug?
Asked
Active
Viewed 124 times
6

CyberSkull
- 796
- 1
- 7
- 16
2 Answers
14
The syntax ^100
is short-hand for 0 ..^ 100
and the ^
means "excluding". 0 ..^ 100
is actually the numbers 0 through 99. That's because with ^100
you get a list with exactly 100 elements - which is very useful for for
loops.
Don't forget you can output the whole list with say (^100).list
.
In addition to that, there's also ^..
and ^..^
which exclude the first element or the first and last element.
-
Ah, I thought the shortcut did `0..100`. – CyberSkull Jan 09 '16 at 12:51
5
The caret ^
indicates that the endpoint is excluded from the range, so 100 is actually not included.
perl6 -e '100 ~~ 100'
will return true
.
Read as: part of the design, cf. https://doc.perl6.org/type/Range

Marvin
- 13,325
- 3
- 51
- 57