Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114545 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74521 invoked from network); 20 May 2021 19:28:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 May 2021 19:28:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CD77E1804D9 for ; Thu, 20 May 2021 12:38: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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 ; Thu, 20 May 2021 12:38:32 -0700 (PDT) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id C23A35C017F for ; Thu, 20 May 2021 15:38:31 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute3.internal (MEProxy); Thu, 20 May 2021 15:38:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=f47L3Nh8HCj7zEoC03U/Kgg2DPcjOiZOVNoN03wwY 8c=; b=qeuf9cfAH50ZOZv6YPquT4RvCr2j8Sw2L4sW2QBbQGHbAV4sIwdsNnU2/ MtQU6sD7Nq0r8aAw1wUvpJy6LWRCrpptNGaNmX7gmGXeULCiks4GNhddWxrHp4WV ildRHczC72qLlQW+xpI6z35qxb9iLm9353lcJ1i6tAUbC+d92ridDqeA/LXP5JsC YzRhr9uLtyh2JRhGCgt6U04XKdHwUgRoVrwt/TxAThTml4epje326wDwxgcS3c8N mbx2p6KDLXSUN53CJVaIdRQqxyjIFORkQ9QEeU4qFc/bajZYuETDhuPDuT+ErECn GP9LajC3LYCSscwDAcK2ftjIs91mQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdejuddgudegtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfn rghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrd gtohhmqeenucggtffrrghtthgvrhhnpeevhfegvdegudefhfelfeeuleevtddvieevhffg veehteeivdfhudffgfeitdeikeenucffohhmrghinhepghhithhhuhgsrdgtohhmpdhphh hprdhnvghtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhho mheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 45F553A0806; Thu, 20 May 2021 15:38:31 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-448-gae190416c7-fm-20210505.004-gae190416 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Thu, 20 May 2021 14:35:35 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] First-class callable syntax From: larry@garfieldtech.com ("Larry Garfield") On Thu, May 20, 2021, at 10:55 AM, Guilliam Xavier wrote: > On Thu, May 20, 2021 at 5:12 PM Nikita Popov wr= ote: >=20 > > On Thu, May 20, 2021 at 4:16 PM Ond=C5=99ej Mirtes wrote: > > > > > Hi, I=E2=80=99m confused by the syntax, when I read it, I think to= myself =E2=80=9CI know > > > this, this is just a method call=E2=80=A6 oh wait, it=E2=80=99s ac= tually a callable=E2=80=9D. It > > > really makes my head hurt. > > > > > > > Yes, I can see how that could be confusing. The current syntax is ch= osen to > > be a subset of the partial function application proposal. However, I= would > > also be happy with some other syntax that makes it clearer that this= is > > acquiring a callable and not performing a call. > > >=20 > Hi, several other syntaxes have been proposed to consideration in the = PFA > thread, and I wouldn't want to start new bikeshedding here; is there a= > place that would be more appropriate to gather the possibilities (like= a > kind of updatable list)? >=20 > Thanks, 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 = from the underlying function" is not viable. It runs into oddball cases= where you may intend to only use one argument but end up using multiple= , especially in array operation functions that sometimes silently pass k= eys along to callbacks if they can. Hence the separate ? and ... that w= ere proposed. * 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 partia= l application, and what does that mean for usability. It gets complicat= ed 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)=20 ** "reduce an arbitrary function to a single remaining argument", which = lets it be used by various existing callback functions in the standard l= ibrary (array_map, array_filter, etc.), many user-space APIs, and the pi= pes RFC that I am planning to bring back up once PFA is figured out (htt= ps://wiki.php.net/rfc/pipe-operator-v2). =20 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 wi= ll 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 ar= gument reordering work because some people asked for it, but as noted th= at'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 combi= nation, 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 workabl= e 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 wan= t (at least I assume we all do), and lots of additional power to boot. = I'd rather see us try to drive PFA home to completion. If that proves i= mpossible by early 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 c= ompeting syntax, in which case no one wins.) --Larry Garfield