Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114478 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34816 invoked from network); 14 May 2021 23:35:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 May 2021 23:35:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DA2C21804E3 for ; Fri, 14 May 2021 16:44:18 -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,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mercury.negativeion.net (mercury.negativeion.net [199.38.81.6]) by php-smtp4.php.net (Postfix) with ESMTP for ; Fri, 14 May 2021 16:44:18 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 3232120D86E729; Fri, 14 May 2021 19:44:18 -0400 (EDT) Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C119QxwsGXyj; Fri, 14 May 2021 19:44:16 -0400 (EDT) Received: from [10.0.1.102] (unknown [173.225.146.47]) by mercury.negativeion.net (Postfix) with ESMTPSA id 322D420D86E71E; Fri, 14 May 2021 19:44:16 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) In-Reply-To: Date: Fri, 14 May 2021 18:44:09 -0500 Cc: Mark Randall , internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <532D1413-52FF-4403-A20B-BBDB51163C85@trowski.com> References: <1565EB81-57B7-49B0-A47C-342E0088A432@trowski.com> To: Paul Crovella X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Partial function application From: aaron@trowski.com (Aaron Piotrowski) > On May 14, 2021, at 6:09 PM, Paul Crovella = wrote: >=20 > On Fri, May 14, 2021 at 2:49 PM Aaron Piotrowski = wrote: >>=20 >> Consider `function foo(int $x, int $y, int $z) {}` with a partial = defined as `$partial =3D foo(?, 42)`. >>=20 >> If the partial is called as `$partial(73, 8)`, should 8 be forwarded = to `$z` or should the call error as providing too few arguments? >=20 > The 8 passes along to $z. There is no error, all required arguments > have been provided. In the current proposal, yes. In a hypothetical implementation where ? = represented a single argument, I was asking what made sense. In that = situation, I think 8 passing along still makes sense. >=20 >> Or perhaps should the partial declaration should error, as it should = have been `foo(?, 42, ?)` or `foo(?, 42, ...?) so the partial provided = all required arguments to foo. >=20 > I think this highlights where the misunderstanding of this feature is. > Partial application is about binding arguments. ? isn't an argument, > it's an argument placeholder. It does two things: signals to create a > closure wrapping the function rather than calling it immediately, and > holds a position in the argument list so that an argument further to > the right can be fixed (bound) at that time. Arguments are bound; > argument placeholders are not, they exist only for convenience. The > syntax `foo(?, 42)` doesn't call foo, let alone provide any arguments > to it, it simply creates a closure that'll pass along 42 at the > appropriate argument position along with whatever else it's provided > with. >=20 > Requiring additional trailing argument placeholders or adding an > additional token `...?` unnecessarily complicates things, burdens the > user, and only serves to further promote misunderstanding. >=20 My issue is the dual-meaning of ? in the current proposal. In `foo(?, = 42)`, the ? represents a single argument, but adding a trailing ? (such = as in `foo(?, 42, ?)`) represents any number of arguments. Would it = perhaps make sense to make superfluous ? markers an error? foo(?); // Fine, needed to define a partial with no bound args. foo(?, 42); // Ok, binds second arg. foo(?, ?, 42); // Ok, binds third arg. foo(?, 42, ?); // Error, unnecessary placeholder. foo(?, ?); // Error, unnecessary placeholder. The intention here is to keep the syntax unambiguous. foo(?) =3D=3D foo(?, ?) =3D=3D foo(?, ?, ?) and so forth is not going to = be obvious to everyone, so why allow meaningless and misleading syntax. Cheers, Aaron Piotrowski