Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100715 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39266 invoked from network); 20 Sep 2017 11:41:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Sep 2017 11:41:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=ilija.tovilo@me.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ilija.tovilo@me.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain me.com designates 17.172.220.114 as permitted sender) X-PHP-List-Original-Sender: ilija.tovilo@me.com X-Host-Fingerprint: 17.172.220.114 st11p02im-asmtp002.me.com Received: from [17.172.220.114] ([17.172.220.114:23086] helo=st11p02im-asmtp002.me.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/06-62331-CC352C95 for ; Wed, 20 Sep 2017 07:41:03 -0400 Received: from process-dkim-sign-daemon.st11p02im-asmtp002.me.com by st11p02im-asmtp002.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0OWK00400TO09U00@st11p02im-asmtp002.me.com> for internals@lists.php.net; Wed, 20 Sep 2017 11:40:58 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=04042017; t=1505907658; bh=T6YRaCc2+tbC8XK+box4iW3+UEa+TuGXnCSL7KZshOA=; h=To:From:Subject:Date:Message-id:Content-type:MIME-version; b=GF1bu1ipFMXyEBktlsY3N+UzbxQxMRiJVTK3TJWwmr6njh6q+PD/hJMGr83z0HY/b KVlaQn/8zRRLqRQ2P6esxRhmW5md18qMmat5N7GtKVHttt331kgd58ck9E0mVZpa63 hCjlZ6tJjzYvfIZu1tmCXi9dn6qxlEhdJNkyJElITaxhkrTs5ILbACs8W1ol/RcKbv v1ieUHCIzknBAmRNJ62sMco9dHhz7UkVid0Ito0NQHSiPZwkk7SnCnHiW5AXsTegKy +lEtg9Xq0Sy7wX5R52L9lO0rcwMf9w/vvNqlt3bp0pQdwFrrRQw+rRfXU0UmL91GA3 dlxZae9rBBJiA== Received: from localhost (st11p02mm-webms001.mac.com [17.172.220.222]) by st11p02im-asmtp002.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTP id <0OWK0014KTS96V10@st11p02im-asmtp002.me.com>; Wed, 20 Sep 2017 11:40:58 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-09-20_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1011 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1709200159 To: Nikita Popov Cc: Sara Golemon , PHP internals Date: Wed, 20 Sep 2017 11:40:55 +0000 (GMT) X-Mailer: iCloud MailClient17FProject126 MailServer17F61.26500-16A-2354-b8decc36e87a Message-ID: <4140cc00-c405-4100-a20d-55113bb46031@me.com> Content-type: multipart/alternative; boundary=Apple-Webmail-42--324771ab-f576-4f11-b75a-2c7a2fde984a MIME-version: 1.0 Subject: Re: [PHP-DEV] [RFC] Pre-draft for PipeOp v2 From: ilija.tovilo@me.com (Ilija Tovilo) --Apple-Webmail-42--324771ab-f576-4f11-b75a-2c7a2fde984a Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8; format=flowed Agree.=0A=0AEven if we already had partial application the previously sugg= ested syntax is still more readable IMO. Consider the following example:=0A= =0A```=0A$array=0A=C2=A0 |> array_map(function ($element) { ... }, $$);=0A= ```=0A=0Avs=0A=0A```=0A$array=0A=C2=A0 |> apply(flip('array_map'), functio= n ($element) { ... });=0A```=0A=0ANot to mention that we'd have to impleme= nt `flip` and `apply` ourselves.=0A=0ARegards=0A=0A=0AOn 20 Sep, 2017, at = 12:01 PM, Nikita Popov wrote:=0A=0AOn Wed, Sep 20, = 2017 at 6:32 AM, Sara Golemon wrote:=0A=0AI was planning= to update the RFC, but wiki.php.net is having issues=0Aatm and isn't comi= ng back up with basic coaxing, so I'll just start=0Adiscussion informally,= and the RFC can be updates later.=0A=0ABackground: I made an RFC some tim= e ago to implement HackLang's Pipe=0AOperator https://docs.hhvm.com/hack/o= perators/pipe-operator which=0Aprovides fluent calling for non-object inte= rfaces.=0AI circulated it to mixed reviews, many negative, with the negati= vity=0Afeeling like it centered on the use of a magic placeholder token `$= $`.=0A=0AAfter discussion with Levi and others who suggested a simpler=0Aa= pproach, I'd like to offer=0Ahttps://github.com/php/php-src/compare/master= ...sgolemon:pipe2 as an=0Aalternate possibility.=0A=0AThis version removes= the $$ token, and instead treats the RHS of the=0Aexpression as a callabl= e obeying the same rules as the callable=0Atypehint elsewhere in the langu= age. Specifically:=0A* Free functions as strings containing the function n= ame. (e.g. 'funcname')=0A* Object methods as array($object, 'methodname')=0A= * Static methods as array('Classname', 'methodname')=0A* Closure expressio= n (e.g. function($x) { return ...; } )=0A* Object instance with an __invok= e() method.=0A=0AIn a given pipe expression, the output of the LHS express= ion feeds a=0Asingle arg to the callable on the RHS.=0AExamples:=0A=0A$x =3D= "hello"=0A|> 'strtoupper'=0A|> function($x) { return $x . " world"; };=0A= // $x =3D=3D=3D "HELLO world"=0A=0ANon-Goal: I didn't include support for = base function names (e.g.=0A`"hello" |> strtoupper`) because of the confli= ct with constants.=0AUsing a constant to store your function name is totes= legit and=0Aconsistent with language syntax.=0A=0AFuture Scope: Short Lam= bdas `$x =3D> $x + 1` and Partial Functions=0A`someFunc('fixed val1', ...,= 'fixed val2')` would help make this=0Afunctionality more useful and are w= orth discussing as a sub-thread,=0Abut are not required to be implemented = at the same time.=0A=0A=0AI think this feature makes very little sense if = it's not introduced=0Atogether with a way of making partial application mu= ch more ergonomic than=0Ait is now. I understand the desire to keep things= separate, but I don't=0Athink that this proposal can land without partial= application syntax being=0Aintroduced beforehand or in conjunction with i= t.=0A=0AFrom a previous R11 discussion, I remember that two strong contend= ers were=0Afoo(...) for getting a callable with an arbitrary number of unb= ound=0Aparameters and foo($$) for a single unbound parameter. In the latte= r case=0Athe proposal has a similar expressive power as the previous pipe = operator=0Aproposal. Another option was to make $$ a more general construc= t for=0Aobtaining single-parameter closures in compact form. Then you woul= d also be=0Aable to write "$$->getFoo()" to get the equivalent of "functio= n($x) {=0Areturn $x->getFoo(); }" and similar. A disadvantage is that the = precedence=0Ahere is less clear and that a short closure syntax might be m= ore clear for=0Athe cases that go beyond partial application.=0A=0ARegards= ,=0ANikita=0A --Apple-Webmail-42--324771ab-f576-4f11-b75a-2c7a2fde984a Content-Type: multipart/related; type="text/html"; boundary=Apple-Webmail-86--324771ab-f576-4f11-b75a-2c7a2fde984a --Apple-Webmail-86--324771ab-f576-4f11-b75a-2c7a2fde984a Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8;
Agree.

Even if we alrea= dy had partial application the previously suggested syntax is still more r= eadable IMO. Consider the following example:

```
$array
  |> array_map(funct= ion ($element) { ... }, $$);
```

vs

```
$array
  |> apply(flip('array_map'), function ($element) { ... });
```

Not to mention that we'd have to implement `flip` and `apply` ourse= lves.

=
Regards


On 20 Sep, 2017, at 12:01 P= M, Nikita Popov <nikita.ppv@gmail.com> wrote:

On Wed, Sep 20, 2017 at 6:32 AM, Sara Golem= on <pollita@php.net> wrote:

I was planning to update the RFC, but wiki.php.net is = having issues
atm and isn't coming back up with basic coaxing, so I'll just start<= /blockquote>
discussi= on informally, and the RFC can be updates later.

Background: I made an RFC some time = ago to implement HackLang's Pipe
Operator https://docs.hhvm.com/hack/operators/pipe-operator w= hich
pro= vides fluent calling for non-object interfaces.
I circulated it to mixed reviews, = many negative, with the negativity
feeling like it centered on the use of a magic = placeholder token `$$`.

After discussion with Levi and others who suggested a simpler=
approac= h, I'd like to offer
https://github.com/php/php-src/compare/master...sgole= mon:pipe2 as an
alternate possibility.

This version removes the $$ token, and instead tre= ats the RHS of the
expression as a callable obeying the same rules as the callable=
typehin= t elsewhere in the language. Specifically:
* Free functions as strings containing = the function name. (e.g. 'funcname')
* Object methods as array($object, 'methodnam= e')
* St= atic methods as array('Classname', 'methodname')
* Closure expression (e.g. functi= on($x) { return ...; } )
* Object instance with an __invoke() method.
=

In a given pipe express= ion, the output of the LHS expression feeds a
single arg to the callable on the RH= S.
Examp= les:
$x =3D= "hello"
|> 'strtoupper'
|> function($x) { return $x . " world"; };
// $x =3D=3D=3D "HELLO w= orld"
Non-G= oal: I didn't include support for base function names (e.g.
`"hello" |> strtoup= per`) because of the conflict with constants.
Using a constant to store your funct= ion name is totes legit and
consistent with language syntax.

Future Scope: Short Lambdas `$x = =3D> $x + 1` and Partial Functions
`someFunc('fixed val1', ..., 'fixed val2')` = would help make this
functionality more useful and are worth discussing as a sub-t= hread,
b= ut are not required to be implemented at the same time.


I thi= nk this feature makes very little sense if it's not introduced
together= with a way of making partial application much more ergonomic than
it i= s now. I understand the desire to keep things separate, but I don't
thi= nk that this proposal can land without partial application syntax beingintroduced beforehand or in conjunction with it.

From a previous R= 11 discussion, I remember that two strong contenders were
foo(...) for = getting a callable with an arbitrary number of unbound
parameters and f= oo($$) for a single unbound parameter. In the latter case
the proposal = has a similar expressive power as the previous pipe operator
proposal. = Another option was to make $$ a more general construct for
obtaining si= ngle-parameter closures in compact form. Then you would also be
able to= write "$$->getFoo()" to get the equivalent of "function($x) {
retur= n $x->getFoo(); }" and similar. A disadvantage is that the precedencehere is less clear and that a short closure syntax might be more clear f= or
the cases that go beyond partial application.

Regards,
Nik= ita
--Apple-Webmail-86--324771ab-f576-4f11-b75a-2c7a2fde984a-- --Apple-Webmail-42--324771ab-f576-4f11-b75a-2c7a2fde984a--