Jump to content

Loops/With multiple ranges: Difference between revisions

m
→‎{{header|Perl 6}}: minor simplifications, style, whitespace tweaks
(added additional notes explaining how a PL/I DO loop works.)
m (→‎{{header|Perl 6}}: minor simplifications, style, whitespace tweaks)
Line 358:
Also displaying the j sequence since it isn't very large.
 
<lang perl6>sub comma { ($^i < 0 ?? '-' !! '') {~ $i.abs.flip.comb(3).join(',').flip }
my $sign = $i < 0 ?? '-' !! '';
$sign ~ $i.abs.flip.comb(3).join(',').flip
}
 
my \x = 5;
Line 371 ⟶ 368:
 
my $j = flat
( -three, *+three … ),
( -seven, *+x …^ * > seven ),
( 555 .. 550 - y ),
Line 384 ⟶ 381:
 
# Or, an alternate method for generating the 'j' sequence, employing user-defined
# operators to more closely mimicpreserve the 'X to Y by Z' layout of the example code.
# Note that these operators will only work for monotonic sequences.
 
sub infix:<to> { $^a ... $^b }
sub infix:<by> { ($^a.split(' '))[0, $^b.abs ... *] }
 
$j = cache flat
-three to 3**3 by three ,
-seven to seven by x ,
555 to (550 - y) ,
22 to -28 by -three ,
1927 to 1939 by one ,
x to y by z ,
11**x to (11**x + one) ;
 
put "\nLiteral minded variantvarient:";
put ' Sum: ', comma [+] $j».abs;
put ' Product: ', comma ([\*] $j.grep: so +*).first: *.abs > 2²⁷;</lang>
10,333

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.