Brace expansion using ranges: Difference between revisions
→{{header|Raku}}: Rearrange, make expand sub self-contained, add some more stringy handling options and fails, test
m (add the extra examples from Wren) |
Thundergnat (talk | contribs) (→{{header|Raku}}: Rearrange, make expand sub self-contained, add some more stringy handling options and fails, test) |
||
Line 1,124:
$incr.=abs;
if try all( +$start
$incr = - $incr if $start > $end;
Line 1,134:
@return = @this.map: { $string.subst($range, sprintf("%{'0' ~ max $sl, $el}d", $_) ) }
}
elsif try +$start
}
else {
if $start.chars + $end.chars > 2 {
return $string if $start.succ eq $start or $end.succ eq $end; # fail
@this = $start lt $end ?? ($start, (*.succ xx $incr).tail …^ * gt $end) !! ($start, (*.pred xx $incr).tail …^ * lt $end);
}
else {
$incr = -$incr if $start gt $end;
@this = $start lt $end ?? ($start, (*.ord + $incr).chr …^ * gt $end) !! ($start, (*.ord + $incr).chr …^ * lt $end);
}
@return = @this.map: { $string.subst($range, sprintf("%s", $_) ) }
}
}
Line 1,150 ⟶ 1,159:
@return = $these.join: ' '
}
}
my $cnt = 1;
while $cnt != +@return {
$cnt = +@return;
@return.=map: { |.&expand }
}
@return
Line 1,169 ⟶ 1,183:
# Test some other features
'stop point not in sequence-{02..10..3}.txt'
steppedAlphaRising{P..Z..2}.txt
'simple {just,give,me,money} list'
{thatʼs,what,I,want}
'emoji {☃,☄}{★,🇺🇸,☆} lists'
'alphanumeric mix{ab7..ac1}.txt'
'alphanumeric mix{0A..0C}.txt'
#
'mixed terms fail {7..C}.txt'
'multi char emoji ranges fail {🌵🌵..🌵🌶}'
> -> $test {
say "$test ->";
say '';
}
Line 1,244 ⟶ 1,243:
rangeless{random}string
stop point not in sequence-{02..10..3}.txt ->
stop point not in sequence-02.txt
stop point not in sequence-05.txt
stop point not in sequence-08.txt
steppedAlphaRisingV.txt
steppedAlphaRisingX.txt
steppedAlphaRisingZ.txt
simple {
simple
simple
simple
simple money list
thatʼs what I want
emoji {☃,☄}{★,🇺🇸,☆} lists ->
emoji ☃★ lists
emoji ☃🇺🇸 lists
emoji ☃☆ lists
emoji ☄★ lists
emoji ☄🇺🇸 lists
emoji ☄☆ lists
alphanumeric mix{ab7..ac1}.txt ->
alphanumeric mixab7.txt
alphanumeric mixab8.txt
alphanumeric mixab9.txt
alphanumeric mixac0.txt
alphanumeric mixac1.txt
alphanumeric mix{0A..0C}.txt ->
alphanumeric mix0A.txt
alphanumeric mix0B.txt
alphanumeric mix0C.txt
mixed terms fail {7..C}.txt ->
multi char emoji ranges fail {🌵🌵..🌵🌶} ->
multi char emoji ranges fail {🌵🌵..🌵🌶}
</pre>
|