Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114417 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7917 invoked from network); 11 May 2021 17:47:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 May 2021 17:47:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 99C001804B1 for ; Tue, 11 May 2021 10:55:34 -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 ; Tue, 11 May 2021 10:55:34 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E39345C012F for ; Tue, 11 May 2021 13:55:32 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Tue, 11 May 2021 13:55:32 -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=nw5OLA mrB8bqXUvqMahraRNcgEnp13dscM+S8IswwgM=; b=URTEBi3sG59elwN6xwpPG5 yueUkIUKqhhsS/DmHo1SnneFSn8jHsdhYRBZoP3zRe7XC5Uif5zC/YCP9uNPmFOO DvvjIn5iT6uA+CjGnMcVEzaeI9PW6jrYmEplqrmGxgRKAB1K3sibJ6wk6RjrKkLE 3wiC4w8GlYEru0sjaUcYSpPKI+bZwZLKyZKjBQMO7kzAjX+/nohoLWhdPqARIhiN SFKH9CkYSuacgzWc4V5GF7/Y8VfwtkwnONzmL84coEtejKdESJ271cNcrdl5RIU7 g1fLh4QkpF0iN18Seew25ggGcl8sHv4tx3wUztjG4cGJ2EbWYY1J5pPSl2vw0iLQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdehtddguddvtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepveehhedvveejledvvefgleevffdtjeekledvkeeg heffgfeivdejhffhledtudetnecuffhomhgrihhnpehphhhprdhnvghtnecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheplhgrrhhrhiesghgrrhhf ihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id A96DC3A04FE; Tue, 11 May 2021 13:55:32 -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: <5650fab5-6006-4af2-b337-9e4aba67bf04@www.fastmail.com> In-Reply-To: References: Date: Tue, 11 May 2021 12:55:12 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Partial function application From: larry@garfieldtech.com ("Larry Garfield") On Tue, May 11, 2021, at 11:57 AM, Nicolas Grekas wrote: > > On Sun, Apr 25, 2021, at 2:25 PM, Larry Garfield wrote: > > > Greetings, Internalians! > > > > > > I would like to offer for your consideration another RFC, specifically > > > syntax for partial function application. > > > > > > https://wiki.php.net/rfc/partial_function_application > > > > > > It includes an implementation by Joe Watkins that is already about 95% > > > complete. (There's some edge cases he's still sorting out, but all of > > > the typical cases should work already.) Most of the design work comes > > > from Levi Morrison and Paul Crovella. I helped out with the tests, a > > > few edge bits, and general instigator/nudge. :-) > > > > > > Discuss. > > > > It looks like the conversation has died down, and it's been two weeks, so > > pending any other notable feedback I'll open a vote on this RFC on Thursday > > or Friday. > > > > --Larry Garfield > > > > LGTM, thanks for the RFC! > > What about visibility? I suppose this works even outside the object scope? > should this be mentionned? > $foo = $this->somePrivateMethod(1, ?) We're pretty sure it will work, and if you return $foo to another caller and then call it, it will work fine. We'll add a test to confirm that. > Would it make sense to support a way to use a placeholder for "all > remaining args"? > Eg: > $foo = some_func(1, ...?) That's already implicit in the way it works now. If you placeholder at least one parameter, and then don't fill in all of the remaining parameters, any additional trailing parameters are always placeholdered. So $obj->foo(?) will always return a partial that has the same arity as foo() does, regardless of how many parameters it has. > Combined with my previous comment, this could replace > Closure::fromCallable() by a language construct, which is something that we > already discussed in another thread (we talked about some ::function > special suffix instead): > $foo = $this->somePrivateMethod(...?) Yep. That's noted in the RFC. Although not the primary intent, a nice side effect is that any_func(?) is now a safe way to turn any function/method into a callable to reference it. That renders ::function or similar 98% unnecessary. (The remaining cases are mostly where you need to collect data statically for compilation or similar.) > In this last form, we might make this result in Closure::fromCallable() > exactly. Aka no increase of the depth of the stack trace. > > BTW, ideally, partial functions should not increase the depth of the > stacktrace at all. Do they? > > Nicolas They currently do, since they work by creating a Closure-esque object called Partial with an __invoke() method. However, if you partial the same thing multiple times then only one stack level gets added. That is: function test($a, $b, $c, $d) { throw new Exception(); } $first = test(?, ?, ?, ?); $second = $first(1, ?); $third = $second(2, ?); $fourth = $third(3, ?); $result = $fourth(4); The stack at the end will contain only one partial "level", not 4. --Larry Garfield