[Could we get the librarian to cc: the RFC owner and hide
replies from the announcement list?]
Perl6 RFC Librarian wrote:
> That is, the expression:
>
> $check = __ < 2 + __ * atan($pi/__) or die __;
>
> is equivalent to:
>
> $check = sub (;$$$$) {
> $_[0] < 2 + $_[1] * atan($pi/$_[3]) or die $_[4]
> };
I *really* like it. If the internals implement this well (and it
has to be *really* fast and slim) this could have enormous impact.
This feature combined with a decent macro system could implement
many core-like special forms in external modules.
> $root->traverse( $sum += __ );
There's a syntactic ambiguity here. I assumed that __ "poisons" an
expression so that an entire parse tree gets transformed into a
closure. If you isolate the parse tree based on expression precedence,
then I'm not sure why the += example works.
And this one is worse:
> $check = sub (;$$$$) {
> @_==0 ? __ < 2 + __ * atan($pi/__) or die __
> : @_==1 ? $_[0] < 2 + __ * atan($pi/__) or die __
> : @_==2 ? $_[0] < 2 + $_[1] * atan($pi/__) or die __
> : @_==3 ? $_[0] < 2 + $_[1] * atan($pi/$_[1]) or die __
> : $_[0] < 2 + $_[1] * atan($pi/$_[1]) or die $_[1]
> ;
> };
Why isn't the ?: operator part of the curry?
I think we need a curry context and that all curries must be surrounded
by parens. There should be a curry prototype for subs too. reduce can be
written as:
sub reduce (_@) { ... }
Curries formed outside of a default curry context must be forced into
the context with curry().
If we adopt curry context and parens, then the __ can be automatically
inserted in some situations.
Here are some examples.
sub traverse ($_);
my $sum = 0;
$root->traverse(($sum += __));
my @flattened = ();
$root->traverse((push @flattened, __));
sub reduce (_@);
$sum = reduce (+) (0, @nums);
$pred = shift || curry(__ ne '');
if (&$pred($x)) { ... }
The use of parens as the curry delimiter is probably a poor choice
because of confusion with function call syntax and list context. I'm
pretty certain the parser could handle it, but I'm not sure about
the perl programmers...
- Ken