Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114422 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22313 invoked from network); 11 May 2021 19:46:09 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 May 2021 19:46:09 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D4E551804B1 for ; Tue, 11 May 2021 12:54:00 -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_H4,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 wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) (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 12:54:00 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 2490817CA for ; Tue, 11 May 2021 15:53:59 -0400 (EDT) Received: from imap8 ([10.202.2.58]) by compute4.internal (MEProxy); Tue, 11 May 2021 15:53:59 -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=Gx4lpW Lj+7EI4Tcg7AuhpkXDvQao7+mSIteT5M8qBeA=; b=FmM1vIyz0ZU/wcslWw2vQq ewNE0De09UO+abmUdJqJS4GjDbUbGwXhTccyUwQdEZe+3/eGWQPXaxpGhyYXt8ik rNNqEmbUSp3QVfHHDxtCDDfwmDqbxcFUH6pAQyk3BQ11WLeJ0N73szDpzghmNA5t CxZCSdmJ8bPva9YSmdeMWMxZcwRiIDwoFMXU15lO1DGHUDCxmGzYjIH7ROxJAWj1 tjxkXHepWoC9J4uw/g2iKyJFa4TLPXv4vbE1n1LeM/sZ+IcpfIcOPDNjHw1zUQeN 4aC9UZGSodziFeuJSOyFjoSLyWmuYRA6raN7DWJOLFxItZL5pP8xuVj6wlKa5eRg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdehtddgudeggecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 78E9B3A04FE; Tue, 11 May 2021 15:53:58 -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: <13142d57-f901-462c-a38f-b146ab36497a@www.fastmail.com> In-Reply-To: References: <5650fab5-6006-4af2-b337-9e4aba67bf04@www.fastmail.com> Date: Tue, 11 May 2021 14:53:37 -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 1:32 PM, Nicolas Grekas wrote: > > > 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. > > > > Nice. Would it be possible to optimize this and remove the extra frame? At > least maybe for the (?) case? I'd have to defer to Joe (he wrote the implementation), but I suspect not. The partial has to be there to carry around the information of what callable to actually call and what the bound parameters are. At that point, it's likely more work to decompose the Partial internally before calling it than to just call the Partial itself. > This makes me wonder: can we create a partial programmatically? Wouldn't > that be needed for some use cases? > Partial::createFromCallable($callable, the-args)? > > Nicolas I cannot think of a use case where that would be needed. Since you can partial-ize any callable, including a dynamic one, if you needed to do something like partial-ize one of a series of function calls you can do that already: $c = match($some_input) { 'A' => 'func_a', 'B' => 'func_b', 'C' => 'func_c', }; $p = $c(1, 2 ?, 4); Though at that point, just partialing them in the first place inside the match would be better as then you never have a function name in a string to begin with. --Larry Garfield