Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114479 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37082 invoked from network); 14 May 2021 23:51:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 May 2021 23:51:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 900FF1804CC for ; Fri, 14 May 2021 17:00:27 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 ; Fri, 14 May 2021 17:00:26 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id EF5875C020C for ; Fri, 14 May 2021 20:00:25 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Fri, 14 May 2021 20:00:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=s+D2dI 9CiSYXpSRP3ybnoycQjRsA1egSjvn1C7AvTzo=; b=ImUp+aZrhfTqst4VQe9BDL sTrEl6fh6F+ZpWQvwlqXEq9znrQ0OWaRQ55Jhu7qT2A5m2StL90cLfqxDZVWG8XG wrDej5zuIzkgad9IohlWa5XjmWHLjW3m05OvXfeISCd5Ky7s5ZViSoe7jfayPclR zgKCMfbmjDH2SGksyhmpC9sgfIh/1nj20MZ4hUeHOMXXmif4c1x1h91rNXuDbl53 Ollt6/jx+ow22QEcB51GhcGeJm7mMJKLLONvwybKzThRj1nl0YyJEsLp4N8rpSVk PwdOecyMnLt3Gzc4JJWpCkPhLxegKucLG+yhFbMpz+uZfbqitPBcAjF+r40u7mBg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdehkedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeejueeuudeiheelkeefjeehfffgieegteetgffhleeg gffggfeifeetvddttdelkeenucffohhmrghinheprghrghhsrdhfohhopdgrrhhgrdhfoh hopdhplhgrtggvhhholhguvghrrdhfohhopdhunhgrmhgsihhguhhouhhsrdhfohhonecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhi esghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id BFA4A3A0130; Fri, 14 May 2021 20:00:25 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-448-gae190416c7-fm-20210505.004-gae190416 Mime-Version: 1.0 Message-ID: <77e233b3-8046-4992-83e4-675d26712091@www.fastmail.com> In-Reply-To: <532D1413-52FF-4403-A20B-BBDB51163C85@trowski.com> References: <1565EB81-57B7-49B0-A47C-342E0088A432@trowski.com> <532D1413-52FF-4403-A20B-BBDB51163C85@trowski.com> Date: Fri, 14 May 2021 19:00:04 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Partial function application From: larry@garfieldtech.com ("Larry Garfield") Mark Randall: > Based on discussions in R11 there seems to be broad agreement that ? > should represent a single argument, and ...? should represent everything > else (including no arguments). This is incorrect. There were a few people arguing for that, but there was far from a consensus on that point. None of the RFC authors were convinced of the arguments given, for example. On Fri, May 14, 2021, at 6:44 PM, Aaron Piotrowski wrote: > > > On May 14, 2021, at 6:09 PM, Paul Crovella wrote: > >> 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. > > > > 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. > > > > Requiring additional trailing argument placeholders or adding an > > additional token `...?` unnecessarily complicates things, burdens the > > user, and only serves to further promote misunderstanding. > > 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(?) == foo(?, ?) == foo(?, ?, ?) and so forth is not going to be > obvious to everyone, so why allow meaningless and misleading syntax. Is that actually going to come up? Given that PHP functions (at least user-space ones) accept extra trailing arguments and just let them fall off, I would *expect* a closure that way to do the same. Named arguments continue that, I believe, by just ignoring any variadic arguments that do not match a parameter in the function. It seems odd to go back on that behavior now. I can't speak for the others, but I could tolerate making "more than one extra ? beyond the end of the parameter list is an error", potentially, as at that point they're redundant. But if a function has, say, 4 params, then fourParams(1, 3, ?) is a convenient way to say "and placeholder everything else". Especially in dynamic cases like Nicolas pointed out, you may not necessarily know how many arguments there are. As Paul noted above, this isn't a syntax for calling a function; it's effectively an even-shorter-hand way to write a short lambda. The rest of the closure construction is derived from the function being partially applied. --Larry Garfield