Hi David,

On 18/05/2021 20:56, David Gebler wrote:
function foo(int $a, int $b, int ...$p) { ... }
$partial = foo(?, 10);

$partial(5, 15, 25);

Intuitively, because the existing convention is extra unused parameters in
user defined functions are silently ignored, I think I would expect the
above to be equivalent to something like:

$partial = fn(int $a) => foo($a, 10);
$partial(5, 15, 25); // 15 and 25 are lopped off to no effect

and not

$partial = fn(int $a, int ...$params) => foo($a, 10, ....$params);

Did you see my message yesterday about the two mental models of the feature? https://externals.io/message/114157#114492

Your expectation there is in line with the "start with an empty closure and add things" model; the behaviour proposed in the RFC is in line with the "copy the full signature and then splice in fixed values" model.

I do worry that users of the language will assume the "wrong" mental model, though, unless we pick a syntax that more clearly matches the "copy and splice" model. I think that would mean having a way to say "make this is a partial", and a way to indicate which arguments to "splice", without any "placeholders".

Yet Another Bad Unsolicited Syntax Suggestion:

$partial = partial foo(); // no bindings; current RFC $partial = foo(?);
$partial = partial foo(b: 10); // bind named parameter $b; current RFC $partial = foo(?, b: 10); $partial = partial foo(1: 10); // bind positional parameter #1 (zero-indexed); current RFC $partial = foo(?, 10);


Regards,

--
Rowan Tommins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to