Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100795 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78626 invoked from network); 28 Sep 2017 19:07:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Sep 2017 19:07:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.51 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 74.125.82.51 mail-wm0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:43935] helo=mail-wm0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 16/61-60510-E884DC95 for ; Thu, 28 Sep 2017 15:07:58 -0400 Received: by mail-wm0-f51.google.com with SMTP id m72so2780187wmc.0 for ; Thu, 28 Sep 2017 12:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=caUrHSIA1bBC36l1PRp5U4Z7Ith5z57rI0so/sWEGT4=; b=CHc3YB1ir7sTCg5YJx/ji+BIcxlEkjcaxAXeWIDljCDYbyY0z+QTJaqCF/TGZ81o4D n0GboUTbUGVoOQNgjmAVR/zJc4n66kuD1EX7+GHADtt8RYy3SdkAfFmJ6qzUpdrzmIF6 Zo1TaADZ68hRKpTP7sOVafz6+dYDRZtoPbPZiNwEFJawET62dsVvIzD6CJV4UhZukNyR KT7KgXfy7hmzteHiJoetFZvM/bZ1KJdrrER0+pXKp5iIqoZ9umv4W4QfRjBI+a7Q+wt9 zg0SkKiMkh4e78wEnWCDU5UyVfEAnOrbmHLmdREEY4LPr2IB9fYfGyzIw24hdImwVPMd /zjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=caUrHSIA1bBC36l1PRp5U4Z7Ith5z57rI0so/sWEGT4=; b=nzuMl1+D5JoaIASkqj1KphBV5jvu1kJhE6duQgI7lNTViDYAAeT20wgHMRpmFKVIZT WkkLho7qg47YuRBBbYtlvUic+06ZZjJNhIrqdhmuKKIxZKzRb5Wn5Ufg1CGymbivW8Iz HuSJRlnRKbuXH/7K72E2iD9XnvcnjEXFz1ulAletgL/jrMAO9pJn6NeDcLmszWX8mPBz udEdr2cMbkC5Fradh0drTEjXM1AHj+8Rlaso0LdZc2X1UkjsxOlXSsnkd97DVGF4H9DE 0TPjDc7fVGCdErfe8Qx3exmp+IaXq7fNqO9E3wWgQJoevxzb/LKIBxzgoyu5S2fcT1pl VJuQ== X-Gm-Message-State: AHPjjUh0klo/QF0DJ6STq30mk7/QmYZv6S2fM83HBEE5uujzabredl/n aiPf+IMWEXdXJEkUKSDMZBGlfrmYKuon9eOst9g= X-Google-Smtp-Source: AOwi7QDmcMv5pQOH0a4/45JGh5ZWrn37IiZFIPkTTUSBq/nrdEK0g6FSM3L/ZND3I/lBGQuwRGGorD+lzgJ3HFFghcw= X-Received: by 10.28.184.151 with SMTP id i145mr1799473wmf.14.1506625675575; Thu, 28 Sep 2017 12:07:55 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.28.193.130 with HTTP; Thu, 28 Sep 2017 12:07:54 -0700 (PDT) In-Reply-To: References: <98e7fff2-72ac-0430-72bb-099a021626f6@gmail.com> Date: Thu, 28 Sep 2017 13:07:54 -0600 X-Google-Sender-Auth: RUi7WtNcQM0RnrtydNt6bJQTNWs Message-ID: To: Sara Golemon Cc: Stanislav Malyshev , PHP internals Content-Type: multipart/alternative; boundary="94eb2c0639e633c6b6055a44a0be" Subject: Re: [PHP-DEV] [RFC] Pre-draft for PipeOp v2 From: levim@php.net (Levi Morrison) --94eb2c0639e633c6b6055a44a0be Content-Type: text/plain; charset="UTF-8" On Wed, Sep 27, 2017 at 1:56 PM, Sara Golemon wrote: > On Thu, Sep 21, 2017 at 5:13 PM, Stanislav Malyshev > wrote: > > It'd be also nice then if we could have some syntax that allowed us to > > refer to functions/methods as callables - mostly for the benefit of the > > code readers and IDEs. I.e. you can do "hello" |> "strtoupper" and it's > > fine but it is not at all intuitive what you're doing sending one string > > into another. Same with "hello" |> [$this, 'bar']. Now, if we could do > > something like this: > > "hello" |> &{strtoupper} > > "hello" |> &{$this->bar} > > > Super-hacky implementation (that I wouldn't want to merge, but it > shows the syntax at work). > > https://github.com/php/php-src/compare/master...sgolemon:lambda > which provides a form of both short-closures and partial functions. > > Combined with also-super-hacky pipe diff from earlier, you get: > > $x = "Hello" > |> &{strtoupper($0)} > |> &{ $0 . "world" } > |> &{strrev($0)}; > > var_dump($x); > // string(10) "dlrowOLLEH" > > -Sara > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > By the way the `&` is not required. When experimenting with possible short closure syntax I created an implementation for `{}` to make sure it was possible: $x = "Hello" |> {strtoupper($0)} |> { $0 . "world" } |> {strrev($0)}; If people would prefer that syntax for short-closures then that's fine by me. If we made it this concise there wouldn't be a need for a `$$` proposal anyway. --- My impression from the community is that the pipe operator is desirable but not if it encourages string or array callables. In that vein which syntax do you prefer? // brace style $x = "Hello" |> {strtoupper($0)} |> { $0 . "world" } |> {strrev($0)}; // fn style $x = "Hello" |> fn($x) => strtoupper($x)} |> fn($x) => $x . "world" |> fn($x) => strrev($0); // caret style $x = "Hello" |> ^($x) => strtoupper($x)} |> ^($x) => $x . "world" |> ^($x) => strrev($0); I included these two styles because they are the most promising versions from the arrow functions discussions. I think my preferred order is the one I wrote them in. The brace style is concise, nicely delimits the expression, and seems the clearest for me to read because the symbols don't dominate. The fn style seems nicer than caret which has too many symbols in close proximity for my taste. Community thoughts? Which short closure style pairs the nicest with the pipe operator? --94eb2c0639e633c6b6055a44a0be--