Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl 6: Difference between .. and ...?

Tags:

raku

What's the difference between .. and ... in Perl 6?

For example, the following lines will produce the same output:

for 1..5 { .say };

for 1...5 { .say };
like image 363
Stefanus Avatar asked Mar 25 '18 18:03

Stefanus


1 Answers

.. construct a range object (think mathematical interval).

... constructs a sequence (think lazily generated one-shot list).

If all I want to do is iterate over consecutive integers (eg for indexing), I prefer he former (it's the less general tool, and a character shorter to boot).

If you need more precise control, use the latter (eg the idiomatic example for generating the Fibonacci sequence in Perl6 is given by the expression 1, 1, *+* ... *, where he third term *+* is the rule for inductively generating the elements).

like image 189
Christoph Avatar answered Nov 16 '22 11:11

Christoph