Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114553 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 29365 invoked from network); 21 May 2021 08:59:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 May 2021 08:59:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 44ACA1804D9 for ; Fri, 21 May 2021 02:09:32 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 21 May 2021 02:09:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1621588169; bh=ZrGv4kt6SBmCb/I4NqFvI/tEyiaD67aPdIGxVSGpNmI=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=lAmu4Rr3XB5IQ/QJadMfeJN6HR92s9KeZ7/MwH+j5aFrRit8mq5U+ReMR+CnVR2Gb MB57ZSHN1dOxuR+KYOa35vgFhikjgw3Wu0QIzr91ma5YXcvNNY3w/tJIGrvOZ+3glN uamnhQuCvQBdg0RrpoqnQ2mJz8pPEQe9NKbXKvZA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MRmjq-1luMDL2ZnG-00TH3d for ; Fri, 21 May 2021 11:09:29 +0200 To: internals@lists.php.net References: Message-ID: <54744b98-27de-4562-d243-77d9e5cba7a9@gmx.net> Date: Fri, 21 May 2021 11:09:32 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Provags-ID: V03:K1:H7s/x9jsAVDrmxwtiWe8uEAaL59Q8BzWn1RY2qEVPrW8anPkHDg oSwy0UdG6ONLFVA/HsQUzFls2KIHw++y86K2SZZ1zALlHypJdncT9Y5xraSUhJaiigM66Ls h9xXh5GwVVVpDs5jwL9609QaZ5B2oPT2LNFHrt36fsQrxZ0I7VDVOMFD0Gdi55Foc8CVKJS ZuELN0AQ1et5mIX9P8noA== X-UI-Out-Filterresults: notjunk:1;V03:K0:4Cc3k6QtMN8=:u8O4qBZkSLU5Mb+kq5MPBG oy5VrI/mJvbgT8ii07rNnP/ANpyzCUZFL8cgr0S0poS2asXK5lUc1lY5kg30UXgva/1pbxVZy kw+CRjb3EJGHGfAtG37W9mWmYmLZ8pOcMMZuGFvyhIsx2mqSTAY6ABmyEFVJuT7Xlbv/zplif iJKHaffpQsJ8GZeUyecBDhuLz1woxrty9ror1W6Q0Nf05fWgoxn+NNXnTXSbOAPTGoOW0EPjd ksVYdW/635qk+xiWJqj7XZ9Fl1u+kqE11FsXQzTb8A0SLBDckqQnIIbJAZaYtO0RlIcfZI5lb adzMVzuBq8L5mjNjkhLLzZ/QxPShX8xwoyHXbSw0vpcpplCttRL42xl85MOxzzOZXwm/wAQh0 BzEk37P+EE6l0IDeiCNkSmoPWckJoBlraUJ8/1jijFYaWewEeiAWvV5bq/ZKmnNspOljwj45S 7gFCEE+F/x0IlzBDrNXoED2O+KLne7JIZSKAvKpnb8LpD99cNVJS4Pq3fHrS6mVbkYbEaiZaI shOmO49gunO3CjeBlunpS+L4bT4ZuMMAwX/sPozIjR2CScnd/D1gCE6egMWig9/VmrIvzc2+y RVGLq5BkOO8q7j4cn/JTAbBzlc0Zvh9PMKLTb/SeIQlaRNg/WErnpzczOqc9tyae/rzlNLDxO G/jba5Ku+GZbBYrB3vKGOjAdEbqa3+TvHpPUS2EOiLGuDGXg3c/DGz5wk9srMVBRzNh/jcigk 0vmou/34wWBMZJsRHOP32zqx7M7ZUlP+JcSc2XXVmGcRsYNacgv2h+eoaGRPHSUjH1WpSDel4 Y5SSQYlqh2OV9B5Sjr88munWS7qaJJV0Qtfsl5N8cGKyGRp8dkLoz0Jl9lb2SkfjQxvv72iCx WOpqkylLD1kvCu9b9ZB8hfhQrqvZRxj05vQiZgF+/8B4zk2ZKiuF+PI4Etgl8ugkgZaZk6e48 p8RYdK1wheucE/lwWmnGHvKKQ7pwhlMu81gwX+P9KKxuYUS1WUuKdhTOcO7NpcXjzwHsheL+I 9Ybnz/VDVQ5UeH/lm6A/SnqJtskFkZCNeYEw4OIJgq98uDSzoq1YxkcldrV8RUj5jsyfXdOb4 z1L528h18/u+AiQnCgQJKIKeS7GeDgrRsJ3NjeI/im2HSktwalDSvVJ1Fmc7WEiIcECp03try AdAiOlRX5qu+T4YbobfzIUwAxexTHr74glqwIUlCPbMYB3C2CWHk7ltA+Tc2Z3p5VOMY8= Subject: Re: [PHP-DEV] [RFC] First-class callable syntax From: a.leathley@gmx.net (Andreas Leathley) On 20.05.21 21:35, Larry Garfield wrote: > There's been a lot of rapid iteration, experimentation, and rejection. > The most recent alternatives are this one from Levi: > https://gist.github.com/morrisonlevi/f7cf949c02f5b9653048e9c52dd3cbfd > > And this one from me: > > https://gist.github.com/Crell/ead27e7319e41ba98b166aba89fcd7e8 > > The main takeaways (to give context to Nikita's proposal): > > * Because of optional arguments, using the same symbol for "copy one par= ameter from the underlying function" and "copy all remaining parameters fr= om the underlying function" is not viable. It runs into oddball cases whe= re you may intend to only use one argument but end up using multiple, espe= cially in array operation functions that sometimes silently pass keys alon= g to callbacks if they can. Hence the separate ? and ... that were propos= ed. > > * Named arguments make things more complicated. One of the questions is= whether named placeholders should be supported or not. And if they are, = does that mean you can effectively reorder the arguments in the partial ap= plication, and what does that mean for usability. It gets complicated and= scope-creepy fast. > > * The most important use cases are: > ** "prefill nothing, just give me a callable" (which is the case Nikita'= s RFC covers) > ** "reduce an arbitrary function to a single remaining argument", which = lets it be used by various existing callback functions in the standard lib= rary (array_map, array_filter, etc.), many user-space APIs, and the pipes = RFC that I am planning to bring back up once PFA is figured out (https://w= iki.php.net/rfc/pipe-operator-v2). > > While there are other use cases, the two of those cover the vast majorit= y of uses. (There is some dispute about which of those is larger, or will= be larger in the future.) > > It took a while to realize the first point, which basically killed "? me= ans zero or more". We also went down a rabbit hole of trying to make argu= ment reordering work because some people asked for it, but as noted that's= a very deep rabbit hole. > > My gist above was a reduced-scope version of Levi's that uses two symbol= s and drops named placeholders. It doesn't give us every possible combina= tion, but it does give us most reasonable combinations. > > Nikita's "just do the first one" RFC (this thread) was proposed at about= the same time, and takes an even-further scope reduction. > > My own take is that the PFA discussion has been overly-bikeshedded, whic= h is unfortunate since I think we're quite close to now having a workable = answer that covers most reasonable use cases. While I agree Nikita's RFC = here would be an improvement over 8.0, I don't think throwing in the towel= on PFA yet is a good idea. It's a much more robust and powerful approach= that still gets us the "first class callable" syntax we all want (at leas= t I assume we all do), and lots of additional power to boot. I'd rather s= ee us try to drive PFA home to completion. If that proves impossible by e= arly July, then this RFC would still get us something this cycle, as long = as the syntax is still compatible with PFA. (Otherwise whenever PFA gets = sorted out in the future we end up with yet-more-ways to do the same thing= that are not optimizations of each other but just competing syntax, in wh= ich case no one wins.) I think Levis proposal and the two symbols ... and ? are a really good improvement to the previous PFA RFC (Nikitas/Joes RFC is a good first step in that direction). I do think named arguments are important, but reordering arguments could be confusing and are not necessary (and if named arguments are used for the PFA, it would make sense to use named arguments for calling it too). Another big reason for me why I like Levis proposal more is that he still includes partially applying the new operator. Although the semantics of the new operator are a bit different from regular functions, it would be very handy to support this special case. array_map is an obvious application: $productObjects =3D array_map(new Product(?, ?, ?), $productIds, $currencies, $prices); But other usages would probably pop up, like abstracting away dependencies of classes by pre-setting those via PFA, like: $productFactory =3D new Product($dependency1, $dependency2, ...); $productObjects =3D array_map($productFactory, $productIds, $currencies, $prices); I really like this because from a users perspective this seems very clear and readable to me, even though from the PHP language perspective it might be more messy. About the bikeshedding: Using "..." as a symbol does make sense to me, as variadic unpacking/variadic arguments have a similar connotation (referring to an unknown/arbitrary amount of elements). * was also suggested (as in "somefunction(*)" instead of "somefunction(...)"), and I like that too - * in regex is any amount of elements (even zero), and ? is exactly one placeholder in SQL. As many PHP developers know regex and SQL this would make PFA code a lot easier to understand even if someone is not that familiar with it yet.