> From: [EMAIL PROTECTED]
> Date: Fri, 7 Feb 2003 16:28:43 -0500
> 
> A4 gives this example of C<for>:
> 
>     for @foo -> $a, $b { ... }  # "for @foo into $a and $b..."
> 
> but, this seems more natural to me (and, it turns out, closer to the P5
> syntax for ill or good):
> 
>     for $a, $b <- @foo { ... } # "for $a and $b from @foo..."
> 
> (heck, that even looks like shifting -- "shifty aliasing". The A4 syntax
> looks like popping until you realize it is really shoving the left N
> thingees into the containers on the right -- Syntactical Action at a
> Distance).

Syntactical Action at a Distance?  The array being iterated over is
near the thing iterating it, C<for>.  The parameters to the block of
code is near the block of code.  

By that logic, though, this is also syntactical action at a distance:

    @foo = @bar;

Since the left n thingies in @bar is getting shoved into the left n
thingies in @foo.  But you wouldn't want @foo to be @bar reversed, for
sure.

Imagine -> as a pipe, and @foo as a queue.

> Then, A4 gives this example of C<grep>:
> 
>     grep -> $x { $x eq 3 } @list # "grep into $x, $ eq 3 from @list"
>     # NOTE: String comparison to a number...
> 
> But, this would match the C<for> example better, IMO (and puts the
> alias name near the source of the things it will be aliasing):
> 
>     grep { $x eq 3 } @list -> $x # "grep $x eq 3 where @list into $x"

If you're talking about your own C<for> example, actually, this would
match it better:

    grep $x <- @list { $x eq 3 }

But if you're talking about A4's:

    grep @list -> $x { $x eq 3 }

Which is very close to (one of) the currently valid:

    grep @list: -> $x { $x eq 3 }

(In Perl 6 there will be many ways to do C<map>s and C<grep> syntactically)

> My guess is that Larry wanted $x to appear before the block it
> will be used in, and that C<grep>'s swapping of block and list
> (when compared to C<for>) makes doing so ugly (IMO).

There has been some inconclusive discussion about unifying those two
syntaxes.  As you can see from my example above, you can get pretty
close, so nobody seems to be complaining anymore.

> But, this would be more natural overall (again, IMO), following my
> suggestion for C<for>, above:
> 
>     grep { $x eq 3 } $x <- @list # "grep $x eq 3 where $x from @list"
>
> Whether what I suggest makes sense to anyone else or not, I do
> think the disparity between C<for> and C<grep> in A4 should be
> dealt with...

I don't think it does.  To me, that is not easier to read by any
means.  Coming from a Western background, I would read that left to
right, and instantly get confused as to what $x was. 

You've read A4, so you should know what -> means (an alias for
C<sub>).  Once you get that stuck in your brain, things will make more
sense.

> ------------------------------------------
> 
> Oh, and A4 also says "Standard Perl declarations will be plainly
> marked with C<my> or C<our>." The C<< -> >> or C<< <- >> notation
> for what amounts to a C<my> should be mentioned nearby, IMO.

Well, you don't say:

  sub foo(my $bar, my $baz) {...}

So you don't when you're using -> either.

> ------------------------------------------
> 
> On another  note, this would seem to be a handy statement modifier
> form for greppage:
> 
>     my @threes = @list when $_ eq 3; # NOTE "where" sounds better

That will not do what you mean at all, though it is syntactially
valid.  What that does is assigns @list to @threes I<only if> $_ is
3.  If you want to do greppage, why don't you just say so:

   my @threes = @list.grep({ $_ eq 3 });

C<when> is just like C<if>, except for deliberately much more DWIMmy.
See the table for =~ (which is now called ~~) in A4.

> although appropriate aliasing syntax for this eludes me at the moment...
> 
>     my @threes = $x <- @list when $x eq 3;
> 
> feels weird with the $x near the '='. 

No kidding. :)

Luke

Reply via email to