Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119693 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 4190 invoked from network); 14 Mar 2023 13:50:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2023 13:50:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BD1951804F8 for ; Tue, 14 Mar 2023 06:50:52 -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-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 ; Tue, 14 Mar 2023 06:50:52 -0700 (PDT) Received: by mail-yb1-f178.google.com with SMTP id c200so5531646ybf.3 for ; Tue, 14 Mar 2023 06:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678801851; 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=GT/rlRhu3W8I5BM8Wq9FvnYR/7dJxBOAdISUf3XRP2c=; b=UFGtYKg+5xyo1CWluT9Jl1CdzjvLXuxdbEMqmonxiFsQ6+ubwrxJTfIFFAEaxpjE28 RMCVUSsNrzgl7xKkPugEEw2BYN5YwQBYIIAOJTx1XNpZI+9KC3HoSLfwXmlfha0ZZszi 4WbWCZZprB64cXVe+3I/VuDR+vREc/9kXP7cpCGFbykwJ2vLxgnLMpIPGw/GZEJMavPX XZQlMWgjAOo8dq7Zys0UPHy5BJZ9lWfkn6TsNz2tEq1rVLcEzSaftv8QVvlplDnHiiWT V0bZA57/OL+yjWV7jec0go57ux6G6rrHlqILL3MQn2Igsp8KOOa1fuVG8i6/6Cr1vvwz Cr6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678801851; 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=GT/rlRhu3W8I5BM8Wq9FvnYR/7dJxBOAdISUf3XRP2c=; b=KHqDYibCCf9yKqhwruoiRbHMGpH4pP5hIJl4a1YvKceyOcz8NmgMHHf8Y01oORX9o4 l5cDlvWa5cZROrBEeoJyXs4+XoViKiTWNh0lfX46gziyb8Irpo9B2EdufFSWJ84j/FYy WX21u3Jl8rt7TkkAWhlttzXr6lqwCQo4ZSs1gjipwXa6tYDJa7PSq/qRTvGPMIKeXcXO Y7aF7h95c+OxYb6/MRvWJvNwJ7C+y653pXpXp2WXVkPHGx9SfzdG3wx/pRLklNZZoyB9 R0lN9PoZDLYm4fE2L8Nk63bcTithRNGSkNwAitbeGArIEBkgTo/+fe6lkJwK4/as4sys ja+w== X-Gm-Message-State: AO0yUKUGlSgpPGJiYr2blJv066yZ4SNJdz7C0c0F+lxtwvb5Ed6L7znp irbg402j2ObgUEB2kCSRHQaBLHIrYxhUSmt9RRHnIL4AlZFq9w== X-Google-Smtp-Source: AK7set/Pcz26I2SE1Wye/9DQ1xuB2Ry8/ezVv9mqMeQf/UGfCKz9MkXfu4MPO6qcuMn/iKkYmgvXijY/P8Ibeedb+G4= X-Received: by 2002:a5b:108:0:b0:8bb:dfe8:a33b with SMTP id 8-20020a5b0108000000b008bbdfe8a33bmr23410620ybx.9.1678801851484; Tue, 14 Mar 2023 06:50:51 -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> In-Reply-To: Date: Tue, 14 Mar 2023 14:50:40 +0100 Message-ID: To: Rowan Tommins Cc: "internals@lists.php.net" 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 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 ... token= ? > > > > Would it not be enough, to simply forbid positional arguments after a .= .. > > and just allow named arguments? These already have well defined positio= n > > independent semantics. > > > > There may be some desire for a single argument placeholder later on, bu= t > > this can be introduced later, separately. > > > > > Yes, named parameters would certainly be better than left-to-right only. > 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 closur= e, > fully positional PFA, and named-after-placeholder PFA: > > $isLogger =3D fn($object) =3D> is_subclass_of($object, LoggerInterface::c= lass, > 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 it'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, fa= lse); // 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.