Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114550 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 17185 invoked from network); 21 May 2021 07:08:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 May 2021 07:08:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8D89C1804E3 for ; Fri, 21 May 2021 00:18:14 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 00:18:14 -0700 (PDT) Received: by mail-ej1-f50.google.com with SMTP id k14so25526951eji.2 for ; Fri, 21 May 2021 00:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uEhxe3D+5o5Q7+kQhImAnxavNwzsIB1Od/t19DT2+qA=; b=hlf2c+QZ54P9sGfvEY069+5ophbZvXvzEizvy7jb0/mV6Du6yR1iVJzu+aj4rRxFzh 0B82nAc/IH5Me+Zrmnfh7myb9DNmQLo37mjNZBh6hT1PXh7+Yc2SqMzYR7iz35SwKo2g 0zYTxsy/cmwemgQmsv4KYMbDSD3+2ZUY6DeqV5Z3lvSSEavnUohpXhqzxQHK651RHM7t R5Gwx0/BG4C9BqehGlSJnZfsBBPRqIm9Po9iiG+K/gQdo91Cv23Yagau3uJnWOJj0UMb 0cwEJabDHYNWB0SrvAq6GmWCtbCeaE0z2nw/8DmLox9DACE+n+DNr3JAcOLsshGDT5gz oz0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uEhxe3D+5o5Q7+kQhImAnxavNwzsIB1Od/t19DT2+qA=; b=omd4lqtlM7q1duUfOgZWu0dvUdSqxi8YDEObAP9PkdqJY0LgaIszAZ6BB3GLA/Yfwj WYapoD1LWp6sRgIKV/4LBjsCUe3DTVzsfv7i05N1zjm7CUMj4Hd1O8QS4ZWWtKdkzKmc pd/amkokvlHEx8yznmsJrqdiR2sNpLPCLVZiIsOgKR2MHVALq4EKm6Y8JmCnP39E4IQN TzRgwUPzA5tb+JoN+8UA4R1G0T5u+4655o+Je5UA05tY3gNP7aZrjiobrfO26t1m0n/e HJGKqvvg4YmifKEejQWhkbkg1LP8NccX8E5rDvAU4HZwZ5SD2bMqdd2vAaJfUa9+VSBc jqvw== X-Gm-Message-State: AOAM5314XvneFa/rjioZajZ4XxME5n7F1mi0LgOlXhJy3gZRxP4KSFS8 7+wBNuvjKRUzyT4NOF78H/LvEq4c1JPTHHeE2N4= X-Google-Smtp-Source: ABdhPJy1Sy2AOBCAU0C8GL7+J/msLPVhgtMLux2uTTBpmYACbL+4HVGmB8K+fthlfowI+rLyEtMI5ZQ9F4KxOzRpnmA= X-Received: by 2002:a17:906:4c82:: with SMTP id q2mr9124836eju.80.1621581489804; Fri, 21 May 2021 00:18:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 21 May 2021 09:17:58 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000ac993905c2d1dc16" Subject: Re: [PHP-DEV] [RFC] First-class callable syntax From: nicolas.grekas+php@gmail.com (Nicolas Grekas) --000000000000ac993905c2d1dc16 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you all for your efforts, I think we're almost there and that PFA would be a really great and useful addition to the language. Le jeu. 20 mai 2021 =C3=A0 21:38, Larry Garfield a =C3=A9crit : > On Thu, May 20, 2021, at 10:55 AM, Guilliam Xavier wrote: > > On Thu, May 20, 2021 at 5:12 PM Nikita Popov > wrote: > > > > > 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 act= ually a > callable=E2=80=9D. It > > > > really makes my head hurt. > > > > > > > > > > Yes, I can see how that could be confusing. The current syntax is > chosen 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. > > > > > > > Hi, several other syntaxes have been proposed to consideration in the P= FA > > 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)? > > > > 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 > parameter from the underlying function" and "copy all remaining parameter= s > 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 keys > along to callbacks if they can. Hence the separate ? and ... that were > proposed. > I've read that some ppl think this should be fought, but that's actually a critical feature of the engine when writing BC layers by adding extra arguments via this possibility. In the 2nd gist, I read "If the current position is a ..., copy all remaining parameters from the underlying function, including a variadic." But to me it's important that all extra arguments are forwarded to the partialized callable, where ... is used or not. Please clarify this point if possible. * 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 > application, and what does that mean for usability. It gets complicated > and scope-creepy fast. > For the userland pov, the principle of least surprise would say we should answer yes to both questions. > We also went down a rabbit hole of trying to make argument reordering wor= k > because some people asked for it, but as noted that's a very deep rabbit > hole. > Then maybe named args should be forbidden for "?" placeholders. This would keep this possibility open of the future and close the "principle of least surprise" expectation if there are. Aka foo(bar: ?) should be a parse error for now at least. My own take is that the PFA discussion has been overly-bikeshedded, which > 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 towe= l > 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 se= e > us try to drive PFA home to completion. If that proves impossible by ear= ly > July, then this RFC would still get us something this cycle, as long as t= he > 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 which > case no one wins.) > I agree. Let's figure out PFAs! If I may add to the bikeshedding, and since PFAs are like others said "short lambas on steroids", what about borrowing the syntax from them? Here would be the first-class callable syntax: fn(...) =3D> $callable(...) and for PFAs: fn(...) =3D> $callable(?, 42, ...) Nicolas --000000000000ac993905c2d1dc16--