Re: [PHP-DEV] Re: [RFC] Partial function application
On Sat, May 29, 2021 at 3:50 PM Mark Randall wrote: > > On 25/04/2021 20:25, Larry Garfield wrote: > > It includes an implementation by Joe Watkins that is already about 95% > > complete. (There's some edge cases he's still sorting out, but all of the > > typical cases should work already.) Most of the design work comes from > > Levi Morrison and Paul Crovella. I helped out with the tests, a few edge > > bits, and general instigator/nudge. :-) > > > Can I be a little pushy and ask for a subvote on "..." vs "...?" > > It _probably_ won't matter, but with ... being used as the language's > universal variadic / unpack, we may use it for similar things in the > years to come, and I think it makes sense to pre-empt a potential > conflict or source of confusion down the line by using "...?". > > Just as a variadic function argument is ...$ a variadic partial closure > would be ...? > > I do not, at this time, have a firm example of where this might become a > problem, otherwise I would state it. The closest I can think of for now > is that it's entirely possible that auto-capturing multiline functions > may end up using: > > $x = function() use (...) { /* */ } > > Which could possibly be confusing. Not a definiative example by any > stretch, but but I do get the feeling that, as we can future proof it > for effectively zero cost, we should. > > Mark Randall I do like the symmetry: Positionals: f($x) --> f(?) Named: f(x: $x) --> f(x: ?) Variadic: f(...$args) --> f(...?) You are right that it _might_ be more future compatible. I don't care about the extra character in this case, as the char does add some visual cue: $callback = $serializer->pack(...); $callback = $serializer->pack(...?); -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php
[PHP-DEV] Re: [RFC] Partial function application
On 25/04/2021 20:25, Larry Garfield wrote: It includes an implementation by Joe Watkins that is already about 95% complete. (There's some edge cases he's still sorting out, but all of the typical cases should work already.) Most of the design work comes from Levi Morrison and Paul Crovella. I helped out with the tests, a few edge bits, and general instigator/nudge. :-) Can I be a little pushy and ask for a subvote on "..." vs "...?" It _probably_ won't matter, but with ... being used as the language's universal variadic / unpack, we may use it for similar things in the years to come, and I think it makes sense to pre-empt a potential conflict or source of confusion down the line by using "...?". Just as a variadic function argument is ...$ a variadic partial closure would be ...? I do not, at this time, have a firm example of where this might become a problem, otherwise I would state it. The closest I can think of for now is that it's entirely possible that auto-capturing multiline functions may end up using: $x = function() use (...) { /* */ } Which could possibly be confusing. Not a definiative example by any stretch, but but I do get the feeling that, as we can future proof it for effectively zero cost, we should. Mark Randall -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php
[PHP-DEV] Re: [RFC] Partial function application
On 25/04/2021 20:25, Larry Garfield wrote: Discuss. There has been intense discussion in R11 about how the ? token applies to missing or variadic arguments. The root of the concern is that in the current proposal, ? applies as either a placeholder for a single replacement, or 0-or-more varadic arguments, depending on its position and the number of arguments. I and several others believe that this feature would be better served by restricting ? to representing a single argument, and using ...? to represent "anything else" including an empty set. ## To illustrate the scope for confusion: foo(?) looks like it requires one argument, when in reality it could accept none, 1, or a hundred. foo(1, ?) looks like it also accepts one argument, but it could accept 0, or 100, depending on the function it is wrapping. foo(?, 1) definitely requires at least one argument, but could accept more depending on what it's wrapping. ## Suggestion Based on discussions in R11 there seems to be broad agreement that ? should represent a single argument, and ...? should represent everything else (including no arguments). Thus: foo(...?) - Partial of foo with all the arguments copied over. foo(?, 1, ..?) - 1 required, then 1 fixed, 0 or more others are copied over. foo(1, ...?) - Fix the first parameter and copy over the rest. This can be seen as a mirror to the ... operator that accepts a variable number of arguments. function foo($a, ...$b) { } Equally it matches the syntax for unpacking into arguments: $a = foo($a, ...$b); Passing more arguments than the partial defines would result in an argument count error. -- Mark Randall -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php