Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119684 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3012 invoked from network); 11 Mar 2023 22:48:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Mar 2023 22:48:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E032918037E for ; Sat, 11 Mar 2023 14:48:33 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,MISSING_HEADERS, 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-yw1-f176.google.com (mail-yw1-f176.google.com [209.85.128.176]) (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 ; Sat, 11 Mar 2023 14:48:33 -0800 (PST) Received: by mail-yw1-f176.google.com with SMTP id 00721157ae682-5416b0ab0ecso41831397b3.6 for ; Sat, 11 Mar 2023 14:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678574912; h=content-transfer-encoding:cc:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=o8Ffhzs0gzxAhvlt06tGfVVETH2DwFEKX3aYqhKAH1A=; b=UBb97n2uU+2zNRtR8SvnjwMkyFx2eNerAfxNWVkcofGm4UDvZAONUIBe3lhQg0u/df /YtmXf4eBzE1JJx5BskRJZ6KV3MFevlSgJD/lBqZqdl37XSqhn9fTNfwFMASUALLSg6c wzlcJcuC6C3bcIfnFriqr3b/i9/UXiNsCG0T0JIsHVZ7MXoZ/k+wrYy9O6ahg+WjtkHC 5zdRwqavLixFrHLA6+TTAL76/6FvtRnmA864ARA4AJNRSQ+3UNqIVvxMD9QU/K8moiNR XRLeeKCZ9Sg4TYqPfRyXLKY4d92896YxVopncHVlK6B+4QBxrQR+whKO73XAWqqUFqDp h4yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678574912; h=content-transfer-encoding:cc: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=o8Ffhzs0gzxAhvlt06tGfVVETH2DwFEKX3aYqhKAH1A=; b=rNTk2sXH07NfkYNpEAu2/B33nwVLLdv55xhFQMqXJQPrQpV84uE+GcgQHUyHfTIph2 JBXRfvNz+2hlNLEVCZBhiiUD8SLUKqkR2pmy9ccNzJEDrCbDG38w5QCLzlK+vjT8CMrk /cjYvoCXQjBD7OmlD3dvp2jJbJtimXBotZPS6OSDxOwyxEF2Zyg08iziohgegSG8BOgC ciJymWNgcjmbnvLu6GEK6v5/IA52e/yqbLYqMvm4wncyhkL0kC9DZV0tvafar6yqrmiE Dj+abfJeAYF2QsiaEwyALqvvmqufSlacRw45rx+5KSAIKTdqnCVWHIC/A00kiIHpk/h1 z+6Q== X-Gm-Message-State: AO0yUKXIwem2w+HNUfT4APHU4XIzYMsu/X9Hyf19uQSfTHK2BAlwGXtu uX/kaW8gYTPxd4JobSKXSXE/OISodZzZEWlXEb/cKGC4Gn0pJmW3 X-Google-Smtp-Source: AK7set97nnHaNFlcn6V2zvtkiunRfvJyd329pzc+VSgtyAZ5HpzTQpSG/WMuLZ8jlbIdVG9k2zrpXXIwNzc8vBocVGo= X-Received: by 2002:a81:a9c6:0:b0:52e:f77c:315d with SMTP id g189-20020a81a9c6000000b0052ef77c315dmr4734489ywh.3.1678574912531; Sat, 11 Mar 2023 14:48:32 -0800 (PST) MIME-Version: 1.0 References: <9975B833-EE24-4ED7-B28E-841B92988BA0@cschneid.com> In-Reply-To: <9975B833-EE24-4ED7-B28E-841B92988BA0@cschneid.com> Date: Sat, 11 Mar 2023 23:48:21 +0100 Message-ID: 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 Fri, Mar 10, 2023 at 10:56=E2=80=AFPM Christian Schneider wrote: > > Am 10.03.2023 um 20:04 schrieb Eugene Sidelnyk : > > Another simplified example: > > > > ``` > > // partial application > > foo(bar(1, ...)); > > While it is not as concise as your version I think the work-around with s= hort arrow functions works ok unless your code is full of partial applicati= ons: > foo(fn(...$a) =3D> bar(1, ...$a)); > > Regards, > - Chris > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > Hey Eugene I actually started on an implementation with this exact syntax this past summer. I stopped after seeing the RFC was already declined years ago. However, there are still some tricky parts to work out. Right now, the "first-class callable" gets (basically) turned into a callable string at the first possible instant, just after parsing. This has to be thrown away, or handled in some other way. In my implementation, I went with treating that as a special case, and basically considering the partial application as 'syntax sugar'. There are also other issues with the grammar, which I'll get to in a few minutes. My "syntax sugar" implementation was that this: return $this->cache->get($command->getPhone(), $this->storeOtp($command, ..= .)); gets turned into this: return fn(...$x) =3D> $this-cache->get($command->getPhone(), $this->storeOtp($command, ...$x)); There were a number of edge cases to solve, but I stopped implementation before I got there. The biggest issue was that the grammar became a little bit ambiguous. I'm sure someone smarter than me can figure out how to define the grammar in a way that isn't ambiguous... but the gist is that the triple-dot is also used for array unpacking, thus I ended up disabling that code path to get it to work. I can probably clean up my code and submit a PR, if anyone would be interes= ted. Cheers, Rob