Damian Conway wrote:
> > And there's no argument about having anonymous, positional, and named
> > placeholders in the redraft...?
>
> There's *always* arguments! ;-)
>
Although arguments from the RFC author are generally more compelling ;-)
> Personally, if we have positional placeholders I don't see the need
> for named ones too. But I'm willing to be convinced.
Well I thought Ken Fox's earlier example was a good one:
> my $f = (^x < ^max) ? ^x * ^scale : ^y * ^scale;
>
> has to be called
>
> &$f($x, $max, $scale, $y)
> <...>
> Seems better to just write $f as:
>
> my $f = (^2 < ^1) ? ^2 * ^0 : ^3 * ^0;
>
> Alright, yeah, maybe not. That's total gibberish isn't it. ;) So how
> about taking the *original* $f and rebinding the order of all the
> arguments:
>
> my $f = &$f(^2, ^0, ^1, ^3);
And the two live together quite nicely, as I described earlier (sorry
Damian, I don't think I cc'd you on the original):
----
<...>
- ^identifier: named placeholder
- ^_: anonymous placeholder
- ^0, ^1, ...: positional placeholder.
Although not necessarily a good idea, these can be mixed in a single
higher-order function:
$icky_func = ^test ? ^2 * ^_ : ^3 * ^_;
First the positional placeholders are filled in (a higher numbered
positional placeholder than the number of parameters results in a
compile-time error). The anonymous and named placeholders fill in the
missing places in the order in which they appear, from left to right.
----
Penultimately, I think it fits better with what the user expects. There's a
nice parallel with '$' as used for:
- $identifier: named variable
- $_: anonymous/default variable
- $digit ...: positional variable from last regexp
Finally, when we have named arguments to functions (which I know you're
working on, creating higher order functions will look very much like
creating normal functions.
So, are you convinced yet?