Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127036 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 465B31A00BC for ; Thu, 3 Apr 2025 21:06:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1743714233; bh=C80K0gl0AveDsXxuo798zFfFxBlM0CyuIPST8UXEGPQ=; h=Date:Subject:To:References:From:In-Reply-To:From; b=SODMyRg7/qfMlCGvYZYgBZSWWVVsiwEQqxALd/qNJYc4PvIwGcz7Zaw052Pia+tls W18kKDH0nCzwLqxW3gZVAvXdXFalXsAIiMkkvxK1WTU+h4t3o3Mcffr1aSvSx0QVJP XrEjLXOkJ/zAqbNMrOuPH+UJiufDdlSNFgN3oc4m1NOf58Iy1AvGFE/mgjeUBgYOBl ue/lUdkD2Cz25Y4eu9G6fx8UNl61kP1Y2xaHUjE+bx14+AfoIhWW3VPjqiQho3Rlmz G5CokLMH7hZUjzQZAOD+TMlgxGqx7EFujlc9/daHCK3P5KDRkvGX+5ajuzPD8fdEKW oXevz/PESQZ3Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 74E54180068 for ; Thu, 3 Apr 2025 21:03:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-b1-smtp.messagingengine.com (fout-b1-smtp.messagingengine.com [202.12.124.144]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 3 Apr 2025 21:03:52 +0000 (UTC) Received: from phl-compute-03.internal (phl-compute-03.phl.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id 8167D1140106 for ; Thu, 3 Apr 2025 17:06:17 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 03 Apr 2025 17:06:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1743714377; x=1743800777; bh=6mIqoZmKq5 jrmxELhAaFpkGQyHO5QhC3QJnJRRE5/Ms=; b=E1fGtMiDxw21JTIzv9XQr47hzp L6Gz4D8oNTHJRlS9IAY24wg7JfjVnHjO88sNuTJ4+E41p6RMMV0Ec9+Pced3NBJ3 cOrylUoMQWCXSDM80aH564UHl9V+QnE+lUvHce/HGOWq50VazHXboCEAg2eKMd+B sHkO2wJ5EW6HQQuOE9X0PXGBnPlVI+L+vwecMdPNpQT1wr3RkcLaRjCR0MSITiuU POo5gMBZSE2tefmx71Kf2yoPbkSoyiFIOP9AZJOCTXdgq+0IpncbExU5HkjFfZTR i0o7AdgosOYUFsCIUFSMlcUqqnQGySI1m/sz0dknoNosIj6c6CAytLMrluow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1743714377; x=1743800777; bh=6mIqoZmKq5jrmxELhAaFpkGQyHO5QhC3QJn JRRE5/Ms=; b=KIw8jSY/JDjbkhevk0bt0hrwxcncLEI0Gl2790cvqtsinBk77fq LyQ1eOvw8MsdEC53q8cFW1VakBisuZT1Xt7yeEp97jYDoTey56rT3WbzoegtjkDF uqAfRQAH6R6sIAW9SiKHRL3MYa01p11TbCH2SdJdLNWzqgvKK29X+yVFTB5pBKfk LoBQcwqiJ14LCoXNFzZQKlttV9f3q1c0KrMCe8C/20l9QFvDwTkB3nVeqUg8CTE7 Zs8yoJmrx32g/Df6In9aGzITr/wynNhVPnfCINrzZiUCZWqRywV+JURpxbCuqjNL Y4rkwPsbJzHVBQVHglDKMPbawcZxd8QjTfA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddukeeliedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpegtkf ffgggfuffvfhfhjgesrgdtreertddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhi nhhsucglkffoufhorfgnfdcuoehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqne cuggftrfgrthhtvghrnhepheetleeiiefgueduieeuieffvdevheduueefkeejuefgffef tdeitdegtedtleetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepihhmshhophdrphhhphesrhifvggtrdgtohdruhhkpdhnsggprhgtphhtthho pedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlih hsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 3 Apr 2025 17:06:16 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------eH0Gz2iZB29rxETD3FYiKLjB" Message-ID: <51df1d77-33ce-414e-b489-8a62f9768811@rwec.co.uk> Date: Thu, 3 Apr 2025 22:06:15 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] Pipe Operator (again) To: internals@lists.php.net References: <5efa2f02-dd1d-4d59-ae07-c75f193b4096@app.fastmail.com> <92b7f1ea-900b-4438-bed7-3fd766bb2d61@rwec.co.uk> <7e2a3dea-aaaf-4427-b1b2-32c568af8b77@app.fastmail.com> Content-Language: en-GB In-Reply-To: <7e2a3dea-aaaf-4427-b1b2-32c568af8b77@app.fastmail.com> From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------eH0Gz2iZB29rxETD3FYiKLjB Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 03/04/2025 18:06, Larry Garfield wrote: > So if we expect higher order functions to be common (and I would probably mainly use them myself), then it would be wise to figure out some way to make them more efficient. Auto-first-arg is one way. From this angle, auto-first-arg is a very limited compiler optimisation for partial application. With auto-first-arg, you have a parser rule that matches this: $foo |> bar($baz); and results in the same AST/opcodes as this: bar($foo, $baz); With PFA and one-arg-callable pipes, you could add a parser rule that matches this, with the same output: $foo |> bar(?, $baz); But you'd also be able to do this: $baz |> bar($foo, ?); And maybe the compiler could optimise that case too. Neither helps with the performance of higher order functions which are doing more than partial application, like map and filter themselves. I understand there's a high cost to context-switching between C and PHP; presumably if there was an easy solution for that someone would have done it already. On 03/04/2025 18:39, Ilija Tovilo wrote: > To me, pipes improve readability when they behave like methods, i.e. > they perform some operation on a subject. This resembles Swift's > protocol extensions or Rust's trait default implementations, except > using a different "method" call operator. > [...] > If we decide not to add an iterator API that works well with > first-arg, then I agree that this is not the right approach. But if we > do, then neither of your examples are problematic. I guess those two things go together quite well as a mental model: pipes as a way to implement extension methods, and new functions designed for use as extension methods. I think I'd be more welcoming of it if we actually implemented extension methods instead of pipes, and then the new iterator API was extension-method-only. It feels less like "one of the arguments is missing" if that argument is *always* expressed as the left-hand side of an arrow or some sort. -- Rowan Tommins [IMSoP] --------------eH0Gz2iZB29rxETD3FYiKLjB Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 03/04/2025 18:06, Larry Garfield wrote:
So if we expect higher order functions to be common (and I would probably mainly use them myself), then it would be wise to figure out some way to make them more efficient.  Auto-first-arg is one way.


From this angle, auto-first-arg is a very limited compiler optimisation for partial application. 

With auto-first-arg, you have a parser rule that matches this:

$foo |> bar($baz);

and results in the same AST/opcodes as this:

bar($foo, $baz);


With PFA and one-arg-callable pipes, you could add a parser rule that matches this, with the same output:

$foo |> bar(?, $baz);

But you'd also be able to do this:

$baz |> bar($foo, ?);

And maybe the compiler could optimise that case too.


Neither helps with the performance of higher order functions which are doing more than partial application, like map and filter themselves. I understand there's a high cost to context-switching between C and PHP; presumably if there was an easy solution for that someone would have done it already.



On 03/04/2025 18:39, Ilija Tovilo wrote:
To me, pipes improve readability when they behave like methods, i.e.
they perform some operation on a subject. This resembles Swift's
protocol extensions or Rust's trait default implementations, except
using a different "method" call operator. 
[...]
If we decide not to add an iterator API that works well with
first-arg, then I agree that this is not the right approach. But if we
do, then neither of your examples are problematic.


I guess those two things go together quite well as a mental model: pipes as a way to implement extension methods, and new functions designed for use as extension methods.

I think I'd be more welcoming of it if we actually implemented extension methods instead of pipes, and then the new iterator API was extension-method-only. It feels less like "one of the arguments is missing" if that argument is *always* expressed as the left-hand side of an arrow or some sort.


-- 
Rowan Tommins
[IMSoP]
--------------eH0Gz2iZB29rxETD3FYiKLjB--