On May 14, 2021, at 7:36 PM, Larry Garfield <la...@garfieldtech.com> wrote:
> 
> On Fri, May 14, 2021, at 7:20 PM, Aaron Piotrowski wrote:
>> 
>>> On May 14, 2021, at 7:00 PM, Larry Garfield <la...@garfieldtech.com> wrote:
>>> 
>>> Is that actually going to come up?  Given that PHP functions (at least 
>>> user-space ones) accept extra trailing arguments and just let them fall 
>>> off, I would *expect* a closure that way to do the same.  Named arguments 
>>> continue that, I believe, by just ignoring any variadic arguments that do 
>>> not match a parameter in the function.  It seems odd to go back on that 
>>> behavior now.
>> 
>> I don't consider forwarding extra arguments an issue. I briefly was 
>> thinking it might be nice to be explicit about the number of arguments 
>> a partial would accept, but you convinced me otherwise in R11, so I 
>> think we're on the same page here.
>> 
>>> 
>>> I can't speak for the others, but I could tolerate making "more than one 
>>> extra ? beyond the end of the parameter list is an error", potentially, as 
>>> at that point they're redundant.  But if a function has, say, 4 params, 
>>> then fourParams(1, 3, ?) is a convenient way to say "and placeholder 
>>> everything else".  Especially in dynamic cases like Nicolas pointed out, 
>>> you may not necessarily know how many arguments there are.
>> 
>> With what I proposed in my last email, `fourParams(1, 3, ?)` is 
>> acceptable, there's nothing superfluous there. At least one ? is needed 
>> to declare a partial. Similarly, a partial for a no parameter function: 
>> `$partial = functionTakingNoParams(?)`. Or even a partial with args 
>> bound to all four params: `fourParams(1, 2, 3, 4, ?)`.
>> 
>> What would error is `fourParams(1, 3, ?, ?)`, as the second ? is meaningless.
>> 
>> I think you've convinced me that one-for-one matching on ? is 
>> burdensome, but the above is a happy medium perhaps?
> 
> I'd be OK with "no more than one trailing ? in excess of what the underlying 
> callable has."  (Which means if you don't know, just stick one ? at the end 
> and you know it will work.)

I think multiple trailing ? should be an error, otherwise how am I suppose to 
know at a glance if a partial declaration will error? Plus it’s adding multiple 
ways to declare the same thing, which I was hoping to avoid.

fourParams(1, 2, ?); // OK
fourParams(1, 2, ?, ?); // OK for you, should error to me
fourParams(1, 2, ?, ?, ?); // Again OK for you, should error to me
fourParams(1, 2, ?, ?, ?, ?); // Error for both

What value is gained in allowing any of those but the first?

I’d also be fine allowing a trailing ? in any declaration. It’s unnecessary, 
but one could argue that it’s consistent to allow a trailing ? in any partial, 
since it’s required for some.

fourParams(?, 2, ?); // Could error, but probably fine for consistency

Aaron Piotrowski

Reply via email to