Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119716 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34778 invoked from network); 15 Mar 2023 20:32:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Mar 2023 20:32:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C08018037E for ; Wed, 15 Mar 2023 13:32:21 -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_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-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 13:32:20 -0700 (PDT) Received: by mail-yb1-f172.google.com with SMTP id n125so7074116ybg.7 for ; Wed, 15 Mar 2023 13:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678912340; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pNpR+ipXohbqaicIN4RAOqJMqAHVb7rbpzn8Brdc/fM=; b=gtPc4FrTnEgF6ldy8mj1zvvREQOHe9cz7bICH4PLQF0rYQ6NcNlIB8N4mnheTT0rp2 4bpNUeFCMz3TAmzoKLJHiLBF/UPBBSRMnRVb6As9W+FfhdURDO4rXttoh/cfgYRUr55O nwhRCSAarKTkDIVbUWi2U32+ushzphbeiXikMHSimbAUx0Abi6+zENuM6TPd9VFez0fZ v3aukYJXWamp4IBQv389gaxywtFLtbphgOU9SgGoBDKJPx4bZPL3zXt/8Uoyp32nviWz zqaYIuGtumR8Bah3Fk8Xo+7IlXyv2h3V9xIxjJRpdKUU3sYUf85+1W0/lfeUCljqYKDR Opew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678912340; h=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=pNpR+ipXohbqaicIN4RAOqJMqAHVb7rbpzn8Brdc/fM=; b=xyEzUoNR5lk5qX9yhtFs22KzokwriM90dxn5VcUzVHnWQX+/cSNmPW5i9TLGIfon79 ORa9701Zir1V+jukvycYWd6v5WJ53Cekpk5YmopBU3//i6oPV7StrX6U5cE+CJi4EEui vajs/T4x7zusyKaBXoyex++Bv0eIxPn5+lk7hEx+g+nGZR3+JuR3OXByOifbsOfspQCG A4R/1NjNmCYWIwizId5NaJhySOEDfx7MyPSsm5IIszpfSXgUcXBw9Zv2Y8c6Tzy93E/q DmFMtxi6C/STj2klczROkvr1FTo859JZWMKO3TaxqVMFF5No0I3Mq13UfNnLGzU6dDEL TRQg== X-Gm-Message-State: AO0yUKU3RUUIImHMdfxo4XdxcZB0z1maC4Fy6z7RcbcNboNG7+IcEKzD rOCt5OBsLqfUFXVtk60kASC5lU0lt1lKOdTP14I= X-Google-Smtp-Source: AK7set8Idzrg3dL2T4qqPfrsgrvuISGkC/WqahK2oWcvqQGpbjGGKCKc8ZdPv0gAy5nLi3lhhVAzgOR2kVhVNHLdSVk= X-Received: by 2002:a5b:542:0:b0:a67:c976:c910 with SMTP id r2-20020a5b0542000000b00a67c976c910mr21843234ybp.7.1678912340068; Wed, 15 Mar 2023 13:32:20 -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: Wed, 15 Mar 2023 22:32:08 +0200 Message-ID: To: Bob Weinand Cc: Rowan Tommins , Garfield Larry , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000a38ece05f6f63d00" Subject: Re: [PHP-DEV] First-class callable partial application From: zsidelnik@gmail.com (Eugene Sidelnyk) --000000000000a38ece05f6f63d00 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 14, 2023 at 12:39=E2=80=AFPM Bob Weinand = wrote: > > > Am 14.03.2023 um 10:16 schrieb Rowan Tommins : > > > > =EF=BB=BFOn 13/03/2023 20:44, Larry Garfield wrote: > >> As has been discussed numerous times, all of the most used array > functions need to be redesigned to work with iterables, and in many cases > make more sense. That would be a natural time to also revisit parameter > order to fit with whatever partial application syntax was in use. > > > > > > It's not just the array functions, though, it's every single function > built into PHP, and an even longer list of userland library and framework > functions; and there will always be competing reasons for preferring one > signature over another. What attracts me about features like PFA is > precisely that they let you work in new ways *without* having to rewrite > all of that. > > > > Some more examples of placeholder-first application, from a quick skim > through the documentation: > > > > $escape =3D htmlspecialchars(?, ENT_XML1); > > $containsAt =3D str_contains(?, '@'); > > $priceFormatter =3D number_format(?, 2, ',', '.'); > > $addSigToFile =3D file_put_contents(?, $signature, FILE_APPEND); > > $takeOwnership =3D chown(?, get_current_user()); > > $encode =3D json_encode(?, JSON_THROW_ON_ERROR | > JSON_PRESERVE_ZERO_FRACTION); > > $unserialize =3D unserialize(?, ['allowed_classes' =3D> false]); > > $isLogger =3D is_subclass_of(?, LoggerInterface::class, false); > > > > I'm sure I could look through Laravel's documentation, or Symfony's, an= d > find examples there too. > > > > Regards, > > > > -- > > Rowan Tommins > > [IMSoP] > > 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 position > independent semantics. > > There may be some desire for a single argument placeholder later on, but > this can be introduced later, separately. > > Bob Personally, I agree with Robert. It seems logical to have ... only at the end of arguments list. Anything else can be bound by positional and named arguments. For instance: ``` str_contains(?, '@'); // do you remember if arg 2 is a needle or a haystack= ? str_contains(needle: '@', ...); // far more readable when explicitly specified explode(?, $str) // do you remember that argument 2 is actual string being exploded (not a delimiter)? explode(string: $str, ...) // delimiter will be provided to the closure ``` On the first stage, maybe it's better to have only positional arguments available without a possibility to provide named ones. I guess this will reveal a lot of pitfalls to consider. For instance, if some third-party library function signature has a signature with a variadic parameter `foo($bar, $baz, ...$x)`. We make a closure for it like this `foo(baz: $b, ...)` and it works fine. Later on authors of a library rename $baz into $tar and it gets unnoticed. Hence, the new signature is `foo($bar, $tar, ...$x)`. How would `foo(baz: $b, ...)` work? Will it put ['baz' =3D> $b] into an $x argument? Firstly, it would make sense to only allow simple use cases of PFA. E.g. only positional parameters. Hence, it won't be possible to use PFA if we want to bind non-prefix parameters. Though, well-designed functions, which declare parameters starting from the most generic unto most specific, will perfectly fit into PFA. --000000000000a38ece05f6f63d00--