List comprehensions: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
SqrtNegInf (talk | contribs) m (→{{header|Raku}}: Fix comments: Perl 6 --> Raku) |
||
Line 1,978: | Line 1,978: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
(formerly Perl 6) |
(formerly Perl 6) |
||
Raku has single-dimensional list comprehensions that fall out naturally from nested modifiers; multidimensional comprehensions are also supported via the cross operator; however, Raku does not (yet) support multi-dimensional list comprehensions with dependencies between the lists, so the most straightforward way is currently: |
|||
<lang perl6>my $n = 20; |
<lang perl6>my $n = 20; |
||
gather for 1..$n -> $x { |
gather for 1..$n -> $x { |
||
Line 1,988: | Line 1,988: | ||
}</lang> |
}</lang> |
||
Note that <tt>gather</tt>/<tt>take</tt> is the primitive in |
Note that <tt>gather</tt>/<tt>take</tt> is the primitive in Raku corresponding to generators or coroutines in other languages. It is not, however, tied to function call syntax in Raku. We can get away with that because lists are lazy, and the demand for more of the list is implicit; it does not need to be driven by function calls. |
||
=={{header|Rascal}}== |
=={{header|Rascal}}== |