"Michael Lazzaro" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Of course, _I'd_ even prefer using <- and -> as the 'piping' operators,
> and having ~> or |> for pointy sub, because then $a->foo and $a.foo
> really _could_ be the same thing, 'cept for precedence. But that's not
> gonna happen, and _I'm_ not gonna press it. :-)
I wouldn't (and don't) give up so easily! The "->" syntax for anonymous
subs is cute: but it seems to be cute only in limited contexts -- those
where it is also being used as a (conceptual) piping operator.
Compare:
$a = sub ($a, $b) { ... }
$x = -> ($y, $z) { ... }
The pointy-arrow doesn't buy anything here.
But in a for loop:
for 1,2,3,4 { ... }
for 1,2,3,4 -> ($a,$b) {...}
its cuteness works because the brain sees it as a piping operator (even
though its not).
Perl6 is still Perl. We're allowed to do a bit of DWIMery in the parser,
if needed, to make the simple (common) cases work. So perhaps we
should define the C<for> in terms of pipelines. With some minor
syntax changes, we can free up the -> operator:
for 1,2,3,4 ~> sub ($a,$b) { ... }
Sure, its not quite so cute. You could rename the C<sub> if desired
(for example, perhaps it could be spelt C<my> in this context, though
you'd need to work on the lexical scoping rules). The only remaining
magic would be to retrofit the basic C<for> to work.
And then we can replace the ~> with ->:
for 1,2,3,4
-> sub ($a, $b) { $a+$b }
-> sub ($a) { $a**2 }
-> { $^foo - 1 }
-> print;
And this begs the question: what exactly does the C<for> contribute to
the semantics of the pipeline? What would C<map> (in void context)
do differently?
Dave.