Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128521 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 lists.php.net (Postfix) with ESMTPS id 7DB661A00BC for ; Thu, 21 Aug 2025 13:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1755784320; bh=JURt8rq1EoE9/JFuwQ2B/9heWcMEpAC65H0Zi+uJulI=; h=Date:From:To:In-Reply-To:References:Subject:From; b=NDMBHUHhmGMScww+FMB7oi8Y6+sVflzlo/UalujR75RINTvPBwPpqOuDZh1qTdSRF SoGcBzvapUNCUAtPmIRXtHNVk5ljUmBLzoN8bgabRRB60eH8hS5D1OnpNcxJvdJUPd onJtvKTghfp+Af9kQ9IRt9p86dCfbUgdOOIAYnuwp7bVBKqGIg8oy8rzt+t/isNB2v AXX0pEkLuZn0WLX2zmb3bG8jNrKhb2eC4opxCAhc0AtpgVP2fAg7Sz5YYfpw1Ssc4x qYbXTjEiREG+K9NJVCjfdmXZuHyhkp9/dXqY5QtzKBxOnGyKcneeCd8/lOnjmdb8r5 /6QX8VYVW6t+Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A6DFE18005C for ; Thu, 21 Aug 2025 13:51:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-b8-smtp.messagingengine.com (fout-b8-smtp.messagingengine.com [202.12.124.151]) (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, 21 Aug 2025 13:51:59 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.internal [10.202.2.50]) by mailfout.stl.internal (Postfix) with ESMTP id 47EB51D00193 for ; Thu, 21 Aug 2025 09:53:33 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-10.internal (MEProxy); Thu, 21 Aug 2025 09:53:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=fm3; t=1755784413; x=1755870813; bh=f34Xa+3VR9s9BfrMXyfxW Gx5JccptO8WH3Mx4ejbd+E=; b=Ft0Uz8TvYkPw6UFPEs3CZ+VRSrNQYsnjgZplv j8R1ABnZJG/iW+sa9ltDwxxhRkdTipHpU8T51ltMvp8vKfrY053BhSVmFPrZu8IH kU9SBF72ptmSP01suZyhTev5VpNLsCvqCTcV/B1oJjr0L2+Wmvfsgz/o2lD679Kt R+jRqlNEUJKWm9dGphUjXi0BGj2H7xWujIaRKSsNmLDSjDFxgcqHCo32eUr+634Y WaspxJkAKUuFXk0vEHM2eheIVgyzw3/PEAUN8S33eVKLvuwtdZKUvn4JWsMcVyPG AuXec3rDk/BQgbacfLVm3CgDgU3X7OsY8HkqCBIpfxWUNfEHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=fm3; t=1755784413; x=1755870813; bh=f 34Xa+3VR9s9BfrMXyfxWGx5JccptO8WH3Mx4ejbd+E=; b=OxAejs3A4GYUZ4/IP +NdgzYdmkWHmRbPhyAwPB+DVQ6Z83CQj7GTwl27Tc4XYAR5Tw+79ftCbCl0xSxTl 9MIIjMJ0Z5b8KOREQTbBLWMadNQqUi9jVR2epNwHH/ZV7PbVEenVnYxKc6dnitAv m28PoZ53BMOgqazX8q5LDrX+J4Cayq22n4ql4FbvXw3D22d6vo1qnmTjhe9nIz7e fTR/yf0GaTn2nmTyvHIkhT+ZexTOq10xydFq0sTCbyqU4EYaNFoWl/pOmwZ7Qf6f Pp83OzqQrIp6Pt4MCHHR4qst05j1vkpeig80hnzUVzpccqXgmr/HufepljycINdI OZ3WA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdduiedugedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthejredtredttdenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeeuvedvudfhffffhfelueehvdejvefgleegteegffetudef leehgeefvdehgeelteenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghl ughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id B6D90700065; Thu, 21 Aug 2025 09:53:32 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: A_uc5gk8jjW7 Date: Thu, 21 Aug 2025 08:53:12 -0500 To: "php internals" Message-ID: <08a0d032-b2f9-4bc6-b44d-f5a02b6ab376@app.fastmail.com> In-Reply-To: <1755766483699.1651677569.3151523711@yahoo.de> References: <1755766483699.1651677569.3151523711@yahoo.de> Subject: Re: [PHP-DEV] Pipe precedence challenges Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Thu, Aug 21, 2025, at 4:07 AM, Hans Krentel wrote: > On Thursday 14 August 2025 21:30:08 (+02:00), Larry Garfield wrote: > >> Does anyone have a better solution to suggest? > > I've been following the discussion on the pipe/short-closure precedence > issue, and while the parentheses-based solution works, it does lead to > syntactic noise that undermines the readability benefits of pipes. > > I'd like to suggest an alternative that turns this problem into an > opportunity for a more elegant syntax. > > Inspired by prior art like Haskell's `do` notation, I propose what I > call "short closure canned pipes." The idea is to leverage the greedy > nature of short closures to define a clean, linear pipe chain within a > closure context. Instead of fighting the precedence, we embrace it to > create a new form: > > > Current problematic example (even with parentheses): > ---------------------------------------------------- > > fn($x) => ($x > |> (fn($x) => array_map(strtoupper(...), $x)) > |> (fn($x) => array_filter($x, fn($v) => $v != 'O')) > ); > > Proposed "canned pipes" syntax: > ------------------------------- > > fn($x) => > |> array_map(strtoupper(...), $x) > |> array_filter($x, fn($v) => $v != 'O') > ; > > > This syntax: > > * Resolves the ambiguity: The `fn($x) =>` explicitly "cans" the value > for the entire pipe chain, making the precedence clear without > parentheses. > > * Reduces boilerplate: It eliminates the repetition of `fn($x) =>` and > nested parentheses, making the code more readable and maintainable. > > * Aligns with intent: It reads as a simple sequence of transformations, > which is the core goal of the pipe operator. > > This approach effectively provides syntactic sugar for the common case > of processing a value through a pipe chain within a closure. It turns > the late-discovered defect into a win for developer ergonomics and > future-proofing. > > I understand that implementation feasibility needs to be assessed, but > if possible, this could be a more satisfying solution than mandatory > parentheses. Thanks to the team for highlighting this issue -- it's > sparked a creative way to enhance the feature. > > Would love to hear thoughts on this. > > Best, > hakre That's an interesting idea, but I don't think it solves the problem. It would make the syntax for pipes-in-closures nicer, yes. However: 1. Ideally, I'm hoping such a pipe-in-closure is replaced with a Composition operator soon enough (https://wiki.php.net/rfc/function-composition), so that wouldn't even be necessary. 2. The main problem is not when a pipe is inside a closure, but when a closure is inside a pipe, which is likely the far more common case. $input |> fn($x) => array_map(strtoupper(...), $x) |> fn($x) => array_filter($x, fn($v) => $v != 'O') ; The problem is this gets interpreted "backwards", with the first closure wrapping around second, rather than being a sibling of it in a pipe chain. A short-hand for pipes-in-closures wouldn't address this issue, which is the more pressing concern. The annoying extra parens there would also be resolved using PFA, which side steps the arrow function in the common case. As the issue is the syntactic parsing of arrow functions, not having arrow functions would also resolve the issue. (As would using higher-order functions instead, which frankly is what I am likely to do 90% of the time myself.) --Larry Garfield