Note:  I'm actually not talking about hyperoperators below, or
map/grep/sort.  Just 'for'.


On Sat, 26 Jan 2002 12:32:06 -0600, Jonathan Scott Duff wrote:

> @result = for @a; @b -> $a; $b { $a op $b }

I'd like to chime in withthe people who have already said that the
semicolons are a bit confusing.

I'd like to propose a slightly different syntax.  Is this maybe valid, or
have I missed a gaping problem?


#   Simplest case: one data source, pulling elements one at a time,
#   operating against a constant
@result = for @a -> ($a)  { $a + 2 }

More formally, this would be:

for LIST -> LIST [[, LIST -> LIST]...] CLOSURE     (returns: LIST)

So, you could write things like so:

#   pull elements off two-by-two
for @a -> $x, $y { ... }

#   flatten @a, @b together, pull elements off two-by-two
for @a, @b -> $x, $y { ... }

#   pull one off @a, one off @b
for @a -> $x,
    @b -> $y
{ ... }

#   pull one off @a, two off @b
for @a -> $x,
    @b -> $y, $z
{ ... }


Of course, all of these only DWIM if -> knows that it takes exactly one
item on the left, and a list on the right.

As an extra bit of magic, perhaps, when the only thing to the left of ->
is a scalar, it could reduce to this (in Perl5 terms):

#   This Perl6:
for $_ -> $x { ... }

#   is the same as this Perl5:
{
  my $x = $_;
  local ($_);
  { ... }
}


Dave Storrs


Reply via email to