Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114490 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 35695 invoked from network); 17 May 2021 02:35:11 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 May 2021 02:35:11 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 76A171804D8 for ; Sun, 16 May 2021 19:44: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=-0.7 required=5.0 tests=BAYES_05,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-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 ; Sun, 16 May 2021 19:44:21 -0700 (PDT) Received: by mail-pj1-f47.google.com with SMTP id pf4-20020a17090b1d84b029015ccffe0f2eso4716930pjb.0 for ; Sun, 16 May 2021 19:44:20 -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=YDak3/BoiSFAuMolPvNaUdS7S7neixyfAh/Tj3tW3GE=; b=pjV+HYGr5ay2/cbq/EWAhq5l58igB0DyOR6PEVAyRcT44a4HEQqlSra7qU16oVC/Ls /TbPOb3ezZk4axANJIoObkyBIxZwPo6/y8LS6Z6dDjLFTMrrwL8zAdjsnpIP3B5qanoZ rHugR5tiFVCJ9MyNjPEJqIUMhsPfporZH4Tu3oLWh9+HPXKlW4TuqWwJEf67KTL9/Act 4cWZzlSung8fKHnSdS7VFZBLo6o+BDRunepejW8YYLJIBQQWjd/iNOim0poV31opVqVX //bD7CmqUvpvP2vmakaWt6nN2PQYcCngiTcr5bqpQZ9BvPFRN81qn4YuGwQTxwtMf92+ /uow== 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=YDak3/BoiSFAuMolPvNaUdS7S7neixyfAh/Tj3tW3GE=; b=LUa4KOBgtKmVkgRAb/eX0XnA/6WiNwT0mZL8JfeedjzJ1N0AbaYmbAIbqvEBNvjGGF 8hcU1GvSc4pCgHl4mofD8zQcRpjVZqFsmmAIdkCk/uHL24wpVpyzU23eO+5KSROloyou pkeQl990QjzSoX+4VIgEzUlbvE+pXhMrmBseS4JhZG+9TDQWGrHeBAuXaqNlAWzo5sS8 /QylwRnHH+uDAKWvntcOMPPEcokd8Xez7H9D7YLvrWwC9FM2/0khokBqiLKDNw/xEHiT mgX/Sz1GwT7LAL1LSWLZ0EIVY0tVgStlYHYnoLT0oHCR0Jv0038xp1GuOIIagtA6VpP9 KMKw== X-Gm-Message-State: AOAM530XRgahYW7CtcbIbj2J6DrdsYDfRmBPbQ/jc4IQXGvJwNp1EH7U ouzVGF2N6JMhgM1YrJRL8AJ84mIU3TSkzQTeO8E= X-Google-Smtp-Source: ABdhPJwMlEyHHF09pFQUKm1UGmq960Kfa9VkXAEhCj8PwBIv7CkuKyZlX57uzdlJbMTkxwBxECk0oDS0X+Wrxn9ltRg= X-Received: by 2002:a17:902:7613:b029:f0:b5b4:6766 with SMTP id k19-20020a1709027613b02900f0b5b46766mr10540680pll.39.1621219458253; Sun, 16 May 2021 19:44:18 -0700 (PDT) MIME-Version: 1.0 References: <1565EB81-57B7-49B0-A47C-342E0088A432@trowski.com> In-Reply-To: Date: Mon, 17 May 2021 07:13:42 +0430 Message-ID: To: Paul Crovella Cc: Aaron Piotrowski , Mark Randall , php internals Content-Type: multipart/alternative; boundary="000000000000e986f205c27d91bb" Subject: Re: [PHP-DEV] [RFC] Partial function application From: hossein.baghayi@gmail.com (Hossein Baghayi) --000000000000e986f205c27d91bb Content-Type: text/plain; charset="UTF-8" On Sat, 15 May 2021 at 09:03, Hossein Baghayi wrote: > Providing ? as a means of placeholder for some arguments and ignoring the > rest could complicate the readability in my opinion. > Maybe we should move (?) out of the arguments list as a means of creating > a partial. > > What I realized is that we need a way of signaling partial function > creation. Be it foo(?) or foo(?, ?, ?) or however many ? is added there, > which does not convey any meaning and also doesn't produce any sort of > error! > > Say instead of foo(?) we had ?foo(). > Since we have named parameters it could help us in providing some of the > arguments and deferring the rest. > > For instance: > ``` > function foo($x, $y, ...$z) {} > > ?foo(); // causes a partial > ?foo(y: '..'); // also causes a partial > ``` > > This way we wouldn't need to worry about the number of ? added to > arguments list. > It may also help in avoiding future PSRs in telling us how many ? we > should put in there :) > In addition to these, I was thinking of 2 other cases in which changing the current proposal might be helpful. 1- When there is a parameterless function (an expensive operation maybe). 2- When all parameters are passed but the function is not expected to be called yet. In the case of a parameterless function, maybe it is an expensive function call and we need to defer calling it. Maybe all we need is to hold a reference to it and pass it around? With the current proposal, I do not know if it is possible or not. Since there are no parameters defined. ``` function with_expensive_operations_lurking_inside() {...} ```` Can we or should we call this function this way: ``` $ref = with_expensive_operations_lurking_inside(?); ``` It feels odd having to provide parameters when there is none needed. For the other use case where all parameters are passed but is not expected to be called yet: Maybe providing parameters and setting it up is not our responsibility. ``` function expensive_or_not($a, $b, $c) {...} $do_not_get_called_please = expensive_or_not(1, 2, 3, ?); // with an extra parameter as to mark as partial! $do_not_get_called_please = expensive_or_not(?, 1, 2, 3); // or maybe this way?! ``` Well, I was thinking that by changing the proposed syntax we could achieve what is proposed and a little bit more. Also we wouldn't need to worry about the number of ? needed as arguments. Since all we need is to mark the return type as partial (closure) on the fly and grab hold of what is passed as arguments. There are some different syntaxes that come to my mind: We could still use ? but outside of the arguments list? ``` $partial = xyx?(..); $partial = ?xyx(..); ``` or maybe different symbols: ``` $partial = :xyz(..); ``` We might be able to even cast the return type: ``` $partial = (?) xyz(..); $partial = (partial) xyz(..); $partial = (fn) xyz(..); ``` --000000000000e986f205c27d91bb--