Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114491 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43515 invoked from network); 17 May 2021 04:49:34 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 May 2021 04:49:34 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9F2291804B0 for ; Sun, 16 May 2021 21:58:44 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 21:58:44 -0700 (PDT) Received: by mail-qv1-f46.google.com with SMTP id u33so2505064qvf.9 for ; Sun, 16 May 2021 21:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ZNlwMhu0BzjOfn/Yfpa5whCv5PQSVP1fIWvEbpi9eDQ=; b=syCmuIWowyBLpbOyPa9lG602sFPEE63dUC1xFz9hXQ4yoPnqb3k6a5iv0YzDRc3Y5l 1ylg/8eI0b810VNPwdyrpdMVz8HWzoBQECBbD8ROwVaRLuwjGPkRpxWTEgjyLe4hIpUH 3GeCAkv8k4G+XTnHp49CIX+bszzo2xGZVbv+0aOHDgmoc6dv8B4terfeTThY4PlARWJa GkBP2p2O+v8QmkzKgT3s9TD+lTLsDpfP05UNVsVzQ+ncVhrKVXnfj5dnA68C2CyVu0Ru 80CxEWpG54Zv6bgCZUvOiPy6N+GdbjCfrsM6R4vgGtQrcieBaH73FajBgS1s0/JiD0Hu IQxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ZNlwMhu0BzjOfn/Yfpa5whCv5PQSVP1fIWvEbpi9eDQ=; b=fYYp6RZQrX1ZyNitxPYaZ5hPbIG5Z8XAjID+rFgGHJEHEzrkx9wA490FYJwA05pmDE Hb3B6n7iVJ8ifld+NOs3KK0e18cyWwCox/2cYOlZr/xkfPvFOJQoDdbnqg2IQM2x1bD5 N7XVjPCJOLKzxRJzEOaFztGoc+xHg/TswbBhDqn9SVAg/1pkAwN0OdWXacSFoo8REWy3 aGqcJHShE20TNtyzxdFR/KN48rY+KITS3zOYde+doHAeBFh6SQ6KAvIs9A2HS49/vcmH RywL+41EAnO9BJGoKSM/pZj8WGXYvku0bLLoSEqYK5MBBmA6FlTvFtGBD3tWGHBtKheu eouQ== X-Gm-Message-State: AOAM533QiBXUeY0BFr3WmQbHZ/YFHMFVJr7f4h1y01dtuKcZei5TN6w9 +Weca//w7h+WdPc8UufGNMAKTA== X-Google-Smtp-Source: ABdhPJyQLiQiVIgC/iibwW+85MLjBPoYalJV3PMZf/2/OO/63iWR3YCQXQDxJ8lQITUkRUqQ20AP9A== X-Received: by 2002:a05:6214:6f1:: with SMTP id bk17mr18551336qvb.37.1621227521788; Sun, 16 May 2021 21:58:41 -0700 (PDT) Received: from [192.168.1.10] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id p10sm9611208qkg.74.2021.05.16.21.58.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 May 2021 21:58:40 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.6\)) In-Reply-To: Date: Mon, 17 May 2021 00:58:39 -0400 Cc: php internals Content-Transfer-Encoding: quoted-printable Message-ID: <09B663C3-E21D-432B-BB7F-78312F827C30@newclarity.net> References: <1565EB81-57B7-49B0-A47C-342E0088A432@trowski.com> To: Hossein Baghayi X-Mailer: Apple Mail (2.3608.120.23.2.6) Subject: Re: [PHP-DEV] [RFC] Partial function application From: mike@newclarity.net (Mike Schinkel) > On May 16, 2021, at 10:43 PM, Hossein Baghayi = wrote: >=20 > On Sat, 15 May 2021 at 09:03, Hossein Baghayi = > wrote: >=20 >> 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. >>=20 >> 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! >>=20 >> 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. >>=20 >> For instance: >> ``` >> function foo($x, $y, ...$z) {} >>=20 >> ?foo(); // causes a partial >> ?foo(y: '..'); // also causes a partial >> ``` >>=20 >> 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 :) >>=20 >=20 > In addition to these, I was thinking of 2 other cases in which = changing the > current proposal might be helpful. >=20 > 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. >=20 > 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 =3D with_expensive_operations_lurking_inside(?); > ``` > It feels odd having to provide parameters when there is none needed. >=20 >=20 > 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 =3D expensive_or_not(1, 2, 3, ?); // with an = extra > parameter as to mark as partial! > $do_not_get_called_please =3D expensive_or_not(?, 1, 2, 3); // or = maybe this > way?! > ``` >=20 > 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. >=20 > There are some different syntaxes that come to my mind: > We could still use ? but outside of the arguments list? > ``` > $partial =3D xyx?(..); > $partial =3D ?xyx(..); > ``` > or maybe different symbols: > ``` > $partial =3D :xyz(..); > ``` >=20 > We might be able to even cast the return type: > ``` > $partial =3D (?) xyz(..); > $partial =3D (partial) xyz(..); > $partial =3D (fn) xyz(..); > ``` Casting is another interesting approach that does feel more consistent = with the existing language. =20 Since it *is* creating a closure, wouldn't this make the most sense? $partial =3D (closure) abc(); $partial =3D (closure) xyz(?,24); -Mike