Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does 100 ~~ ^100 return false in Perl 6?

Tags:

raku

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?

like image 976
CyberSkull Avatar asked Jan 09 '16 11:01

CyberSkull


1 Answers

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.

like image 160
timotimo Avatar answered Sep 22 '22 23:09

timotimo