Ken Fox wrote:
> Jeremy Howard wrote:
> > Anyhoo, there's no reason why you can't have ^1, ^2, and so forth, _and_
> > allow named placeholders too. Although I don't see what this buys you.
>
> Argument ordering. We might be constrained by the caller as to what order
> the placeholders are passed in. Also, we want to make partial application,
> i.e. recurrying, as useful/simple as possible. So it's important to
> have the argument order independent of where the placeholders appear
> in the expression.
>
True. That is important.

>   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);
>
Nice.

> Anyways, ^_ has my vote.

So is this a consensus?:
----
It is proposed that Perl introduce a new prefix '^', which indicates a
placeholder. This can be used in any of the following ways:
- ^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.

However, for the good of international mental health, you may want to
consider using a consistent approach within a single higher-order function
definition.
----
> (Although I really have a soft spot for that
> Oracle SQL*Plus variable syntax... ;)

<Cough, splutter> Please, there are children present...


Reply via email to