I found myself writing a perl script today in which I did (I'll
perl6-ize it for sake of discussion):
for 98,99 -> $i {
for 0..255 -> $j {
# testing IP addresses with $i.$j
}
}
I was thinking about what would happen if I allowed the user to input
those ranges, like:
67.173.[98,99].[0..255]
After appropriate data massagng, I'd have to do something like:
for @(@ranges[1]) -> $i {
for @(@ranges[2]) -> $j {
for @(@ranges[3]) -> $k {
for @(@ranges[4]) -> $l {
# ...
}
}
}
}
Using a permutations module I could make that shorter, but I figure that
since we're already providing C<zip> to make looping easier, why not
provide C<outer> (perhaps spelled Â)? The outer function would provide
a way to I<dynamically> nest loops.
for outer([EMAIL PROTECTED]) -> [ $i, $j, $k, $l ]
{
# ...
}
Or better yet:
for outer([EMAIL PROTECTED]) -> @cp {
my $ip = @cp.join('.');
}
And the original loop could be written:
for 98,99 Â 0..255 -> [$i, $j] {
# ...
}
Supposing  had sufficiently low precedence. And supposing  were used
at all, something I'm not particuarly attached to happening.
I believe it could be programmed lazily. Like this:
sub _outer_coro(*$first is context(Scalar),
[EMAIL PROTECTED] is context(Scalar))
is coroutine
{
if @rest {
_outer_coro [EMAIL PROTECTED];
}
else {
yield $first;
}
}
sub outer([EMAIL PROTECTED] is context(Scalar))
{
<_outer_coro([EMAIL PROTECTED])>
}
Luke