Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100798 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12909 invoked from network); 29 Sep 2017 09:30:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Sep 2017 09:30:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=michal@brzuchalski.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=michal@brzuchalski.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain brzuchalski.com designates 188.165.245.118 as permitted sender) X-PHP-List-Original-Sender: michal@brzuchalski.com X-Host-Fingerprint: 188.165.245.118 ns220893.ip-188-165-245.eu Received: from [188.165.245.118] ([188.165.245.118:33155] helo=poczta.brzuchalski.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1A/E0-34435-7921EC95 for ; Fri, 29 Sep 2017 05:30:01 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 13E73298423C for ; Fri, 29 Sep 2017 11:29:57 +0200 (CEST) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Acv29vIx2izX for ; Fri, 29 Sep 2017 11:29:50 +0200 (CEST) Received: from mail-oi0-f51.google.com (unknown [209.85.218.51]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id BDC79298423A for ; Fri, 29 Sep 2017 11:29:49 +0200 (CEST) Received: by mail-oi0-f51.google.com with SMTP id b184so1101707oii.13 for ; Fri, 29 Sep 2017 02:29:49 -0700 (PDT) X-Gm-Message-State: AMCzsaW6yJ0/lm1K+H3TSPYinNHgLf8m3BTgeUUJJJGEQPKkIkqLpcW7 j4jqTkJq3B3iNb6yHrCXBXrVh05Xq3vVN37jKzI= X-Google-Smtp-Source: AOwi7QCArVRyrMsTGEFaopx9UBHeBcphmNUSr/xi20z9YWBhXTzWhGlW5LBtn3ozLS4UZSD3fCk/EhmpiuenTYL9Umo= X-Received: by 10.157.27.99 with SMTP id l90mr2294359otl.169.1506677388749; Fri, 29 Sep 2017 02:29:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.168.183.136 with HTTP; Fri, 29 Sep 2017 02:29:48 -0700 (PDT) In-Reply-To: References: <98e7fff2-72ac-0430-72bb-099a021626f6@gmail.com> Date: Fri, 29 Sep 2017 11:29:48 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Levi Morrison Cc: Sara Golemon , Stanislav Malyshev , PHP internals Content-Type: multipart/alternative; boundary="94eb2c09c3028c34d6055a50aaec" Subject: Re: [PHP-DEV] [RFC] Pre-draft for PipeOp v2 From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --94eb2c09c3028c34d6055a50aaec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2017-09-28 21:07 GMT+02:00 Levi Morrison : > 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 t= o > > > refer to functions/methods as callables - mostly for the benefit of t= he > > > 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 d= o > > > 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 =3D "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 shor= t > closure syntax I created an implementation for `{}` to make sure it was > possible: > > $x =3D "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 `$$` propos= al > anyway. > I love this syntax with braces, I wanted to do like it in https://wiki.php.net/rfc/short-closures but only for replacement of string or array callables as closures. > > --- > > My impression from the community is that the pipe operator is desirable b= ut > not if it encourages string or array callables. In that vein which syntax > do you prefer? > > // brace style > $x =3D "Hello" > |> {strtoupper($0)} > |> { $0 . "world" } > |> {strrev($0)}; > > // fn style > $x =3D "Hello" > |> fn($x) =3D> strtoupper($x)} > |> fn($x) =3D> $x . "world" > |> fn($x) =3D> strrev($0); > > // caret style > $x =3D "Hello" > |> ^($x) =3D> strtoupper($x)} > |> ^($x) =3D> $x . "world" > |> ^($x) =3D> 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 o= ne > 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? > --=20 regards / pozdrawiam, -- Micha=C5=82 Brzuchalski about.me/brzuchal brzuchalski.com --94eb2c09c3028c34d6055a50aaec--