On Tue, 14 Mar 2023 at 10:39, Bob Weinand <bobw...@hotmail.com> wrote:

> Hey Rowan,
>
> do we actually need *positional* partial application, after a ... token?
>
> Would it not be enough, to simply forbid positional arguments after a ...
> and just allow named arguments? These already have well defined position
> independent semantics.
>
> There may be some desire for a single argument placeholder later on, but
> this can be introduced later, separately.
>


Yes, named parameters would certainly be better than left-to-right only.
It's definitely less elegant, though, and given that PFA is largely
short-hand for a short closure anyway, I think conciseness is quite an
important aim.

To take a couple of the above examples, and compare existing short closure,
fully positional PFA, and named-after-placeholder PFA:

$isLogger = fn($object) => is_subclass_of($object, LoggerInterface::class,
false);
$isLogger = is_subclass_of(?, LoggerInterface::class, false);
$isLogger = is_subclass_of(..., class: LoggerInterface::class,
allow_string: false);

$priceFormatter = fn(float $num) => number_format($num, 2, ',', '.');
$priceFormatter = number_format(?, 2, ',', '.');
$priceFormatter = number_format(..., decimals: 2, decimal_separator: ',',
thousands_separator: '.');

Arguably the named param version is more explicit, but in some cases it's
significantly longer than manually defining a closure, whereas fully
positional PFA is always shorter.

Regards,
-- 
Rowan Tommins
[IMSoP]

Reply via email to