Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119707 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91136 invoked from network); 15 Mar 2023 10:17:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2023 10:17:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7B4AE1804AC for ; Wed, 15 Mar 2023 03:17:16 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 15 Mar 2023 03:17:16 -0700 (PDT) Received: by mail-yb1-f170.google.com with SMTP id p203so11433961ybb.13 for ; Wed, 15 Mar 2023 03:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678875435; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IErM2B0/61jevXATrYi+VKpb9qrjoPVttbdvV34dkhU=; b=WuMcmuq5JkGbtXoqZbTou2m7Ybm6U2AMLLUeSqi2uShdRsKzV4c4oCA0/6MYtvGiXM sEFlnTD2dWZofWI43CwImdcB7a5qO4DWAabwLTpw7/TLQ0C2fdnvnjLAWOO4VX0pyLVI 8Uedfosicgu01ZO9GyRh92Iq5wYhV+5hX8TQqsNc2PciaTr7h41urf7m+ZzQTIe071lb qBEqDQVYbQApvWzguvNtMY7aW6fWYlOZzIqp5CZx10K1ZxNHk/v/5F+trjSYim86SnQJ oskheRYEAixrPLHECMdVpEeonkVaGT9xLiUeTj6xnHW0B++DQl78uAS9WcxvisHNTh7Z 0mXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678875435; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IErM2B0/61jevXATrYi+VKpb9qrjoPVttbdvV34dkhU=; b=Bw4APKkPhn4Sl1uJgWLcfMnoTPW3tP201x0Lm4fm9ZoJ90Z5Utj+yPj5VZf72J354U JAYDMNUPTMgbNIKS7fupb+W3Hyq8YGDN3ik06dUoahhe7HAMYzetCIseu9x5whQBk4Ug MqeZf3lfP5K7yqvvtxSdyJAmL7ITKnrOut1E+HOpdRi8ZbZFC4Hep6I1PjWxEjx1og6V bUlB4+EgsxSDt/5MhWTmn5Undo4VbSoSalVBdAMUM4blpfzrbrmwIR4KVN/g8qeOxqQD n77VYPofDpxr/wRu7NZVd6RnzYAjgHiNaiOazP+y41nW1dcIT2+1/1UcN0Ee8isZ5hwx /V4w== X-Gm-Message-State: AO0yUKXbo7YU54HcW48WmyNPTx9fBS0P0nUrtu8fdSzTnm5EZ2zo4kly 1DQ2zg9dHyfgoPbbiSFhyBgV244v7uEec6cKf3XTvic6K4hdWC8d X-Google-Smtp-Source: AK7set9QJVAk2Gu2K/ad/ud2LR7KUtYQKjflmf92MzBfw6mv4dSlqYSap6SuA7UsTT9BfQ/3k9kbk0hoIW5inl1iOgQ= X-Received: by 2002:a25:f50a:0:b0:b46:4a5e:3651 with SMTP id a10-20020a25f50a000000b00b464a5e3651mr3096141ybe.9.1678875435362; Wed, 15 Mar 2023 03:17:15 -0700 (PDT) MIME-Version: 1.0 References: <9975B833-EE24-4ED7-B28E-841B92988BA0@cschneid.com> <1A2CE63B-ECCA-403D-83AC-B1E26279323C@gmail.com> <9a2140b4-97bb-4a9c-90c5-809274c83f75@app.fastmail.com> <88c4a63c-859b-94d5-e314-3399fb2c3fb0@gmail.com> <1a4d4434-7318-4831-9fc0-8b48a6400a62@app.fastmail.com> In-Reply-To: <1a4d4434-7318-4831-9fc0-8b48a6400a62@app.fastmail.com> Date: Wed, 15 Mar 2023 11:17:04 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] First-class callable partial application From: landers.robert@gmail.com (Robert Landers) On Tue, Mar 14, 2023 at 5:58=E2=80=AFPM Larry Garfield wrote: > > On Tue, Mar 14, 2023, at 8:50 AM, Robert Landers wrote: > > On Tue, Mar 14, 2023 at 1:57=E2=80=AFPM Rowan Tommins wrote: > >> > >> On Tue, 14 Mar 2023 at 10:39, Bob Weinand wrote: > >> > >> > Hey Rowan, > >> > > >> > do we actually need *positional* partial application, after a ... to= ken? > >> > > >> > Would it not be enough, to simply forbid positional arguments after = a ... > >> > and just allow named arguments? These already have well defined posi= tion > >> > independent semantics. > >> > > >> > There may be some desire for a single argument placeholder later on,= but > >> > this can be introduced later, separately. > >> > > >> > >> > >> Yes, named parameters would certainly be better than left-to-right onl= y. > >> It's definitely less elegant, though, and given that PFA is largely > >> short-hand for a short closure anyway, I think conciseness is quite an > >> important aim. > >> > >> To take a couple of the above examples, and compare existing short clo= sure, > >> fully positional PFA, and named-after-placeholder PFA: > >> > >> $isLogger =3D fn($object) =3D> is_subclass_of($object, LoggerInterface= ::class, > >> false); > >> $isLogger =3D is_subclass_of(?, LoggerInterface::class, false); > >> $isLogger =3D is_subclass_of(..., class: LoggerInterface::class, > >> allow_string: false); > >> > >> $priceFormatter =3D fn(float $num) =3D> number_format($num, 2, ',', '.= '); > >> $priceFormatter =3D number_format(?, 2, ',', '.'); > >> $priceFormatter =3D number_format(..., decimals: 2, decimal_separator:= ',', > >> thousands_separator: '.'); > >> > >> Arguably the named param version is more explicit, but in some cases i= t's > >> significantly longer than manually defining a closure, whereas fully > >> positional PFA is always shorter. > >> > >> Regards, > >> -- > >> Rowan Tommins > >> [IMSoP] > > > > Something I was partial to (pun slightly intended), when thinking > > about it last summer was to put named parameters with dots following, > > like this: > > > > $isLogger =3D is_subclass_of(object_or_class..., LoggerInterface::class= , false); > > // or, since this is a beginning/end partial, this is the same: > > $isLogger =3D is_subclass_of(..., LoggerInterface::class, false); > > > > $isLogger(object_or_class: $myClass); > > // or > > $isLogger($myClass); > > > > $priceFormatter =3D number_format(num..., 2, ',', '.'); > > > > At least, that was what I was going to propose, according to my notes. > > Looking at it 8 months later, I still kinda like it. > > For reference, in the original RFC we had the following rules: > > ``` > This RFC introduces two place holder symbols: > > The argument place holder ? means that exactly one argument is expect= ed at this position. > The variadic place holder ... means that zero or more arguments may b= e supplied at this position. > > The following rules apply to partial application: > > ... may only occur zero or one time > ... may only be followed by named arguments > named arguments must come after all place holders > named placeholders are not supported > ``` > > The reason for that was, I believe, because it was too complicated figure= out the signature of the resulting closure if named placeholders were allo= wed after the `...` . Optional arguments also got weird, IIRC. We went ar= ound *a lot* on the details here before settling on the syntax we did. > > I agree that requiring all partials to used named args would be a big ste= p down for usability. > > But again, none of this addresses the root issue that doomed the previous= RFC: Any syntax that involves a runtime determination of "is this a functi= on call or a partial application?" is going to involve some really tricky d= ancing along the critical path of all function calls. Even though Joe's im= plementation had no significant performance impact (AFAIR), it still made t= he code more complex and potentially harder to optimize in the future. > > So the only ways forward would be: > > 1) Find another approach in the implementation that doesn't have that pro= blem, which may then changes to the proposed syntax and possibility capabil= ities. (I had suggested some prefix on the call to indicate that it's a pa= rtial and not a call, like %foo(1, ?, 3, ...) or something.) > 2) The voter base shifts and/or changes its mind and decides that the ext= ra complexity is worth it. > > Redoing the syntax bikeshedding from 3 years ago (dear god, it's been 3 y= ears?) before one of those two is answered is not productive. New engine a= pproach first, then syntax based on what that approach allows. > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Hey Larry, > Redoing the syntax bikeshedding from 3 years ago (dear god, it's been 3 y= ears?) before one of those two is answered is not productive. New engine a= pproach first, then syntax based on what that approach allows. This is why my approach was one of syntax sugar. Sure, it would make the call stack weird during exceptions, but all-in-all, not much changes from an engine standpoint. Most of the changes were to the grammar IIRC. I'll hop on my old computer this weekend and submit a PR to make the discussion easier.