Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100711 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28893 invoked from network); 20 Sep 2017 10:01:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Sep 2017 10:01:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.173 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.223.173 mail-io0-f173.google.com Received: from [209.85.223.173] ([209.85.223.173:56778] helo=mail-io0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 65/84-62331-86C32C95 for ; Wed, 20 Sep 2017 06:01:13 -0400 Received: by mail-io0-f173.google.com with SMTP id m103so3521590iod.13 for ; Wed, 20 Sep 2017 03:01:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Aow5mBVFO65BE6l+CEKli7IbpzEye9JHPUVlwaAq1Fg=; b=qPh28QXurumTZG2Jq1u2tyXK649NmkDPeNuMdQIeSJ/F0RZfn6bkB11cmrxh1ilfrf Ff5CZTVlTzIzLBpsZbydOoT4dqnCQq8hxioLzSMzlBDQmOhxMNdNvLffxDxAARtE9O28 LTONuJZ95K9NOSaJhvbkYcMUH+XVpsHovO/Pssx3eN7rd1z4sUU2BhiKFby9Q1T+BMVY VXeH2Nuj6fVZDVR0++si9JAKIReMmR+QCHpw6TFBdW2uuMFtHamY6xI6Ou7O1WGyV/VY OEvfm477cK1IGsjQgyWIEHDFL+J3Rxfj+hWMv0S253nmpbXhwhJ+UqBtbRfFC0h+wBUq 6E0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Aow5mBVFO65BE6l+CEKli7IbpzEye9JHPUVlwaAq1Fg=; b=JDWLhFWcQq45JOrXEy6uPowNCBTi3AUbJex75x9ffNnv69Z7UxefJx11qFq8ysIOZz oteBsaof6i8pgede/fB+Q/rHa9qDdd4EWZC3N3MAcM/yw65yIaSzB5h517hSqRfSihez rLJLqA0En2pb17MEpGuIoHwyeCCSun6kRCoWNrmu7llhzKUlsFo20QP7NXZLKkaeRwM8 FxWDdMK0tbHYSkDApPXPiCCbOhe/4GYWtdXXWRO/O+jjUp4+kkA66ylVD/MtHDwc1Izu Cdp3LuweJraJC/8ZUlZ0HTKRLAWG/763sMyyaXTKJ8KsCtQ6oawTkaWcvcxlQtiDUaDq YZ9Q== X-Gm-Message-State: AHPjjUgtYYbNUnhEGLvDQj6Y2i2by80wVGRycK0lLp06302MyCshcMtU XSEwcHT04rIzhMdZHkPLzFSWylhHvDL0pDG0His= X-Google-Smtp-Source: AOwi7QA46lG/jsS5HcGEkfcxB9Da0gFB9jKEsmVlXPVhSUiiyift1ca0GUtMfweiZU1dTSYueDiIFgzjiEOaAndXnkA= X-Received: by 10.107.137.213 with SMTP id t82mr6584024ioi.289.1505901670117; Wed, 20 Sep 2017 03:01:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.34.209 with HTTP; Wed, 20 Sep 2017 03:01:09 -0700 (PDT) In-Reply-To: References: Date: Wed, 20 Sep 2017 18:01:09 +0800 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: multipart/alternative; boundary="001a113eccb61d477c05599c0e3e" Subject: Re: [PHP-DEV] [RFC] Pre-draft for PipeOp v2 From: nikita.ppv@gmail.com (Nikita Popov) --001a113eccb61d477c05599c0e3e Content-Type: text/plain; charset="UTF-8" On Wed, Sep 20, 2017 at 6:32 AM, Sara Golemon 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 > discussion 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 which > provides 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 > approach, I'd like to offer > https://github.com/php/php-src/compare/master...sgolemon:pipe2 as an > alternate possibility. > > This version removes the $$ token, and instead treats the RHS of the > expression as a callable obeying the same rules as the callable > typehint elsewhere in the language. Specifically: > * Free functions as strings containing the function name. (e.g. 'funcname') > * Object methods as array($object, 'methodname') > * Static methods as array('Classname', 'methodname') > * Closure expression (e.g. function($x) { return ...; } ) > * Object instance with an __invoke() method. > > In a given pipe expression, the output of the LHS expression feeds a > single arg to the callable on the RHS. > Examples: > > $x = "hello" > |> 'strtoupper' > |> function($x) { return $x . " world"; }; > // $x === "HELLO world" > > Non-Goal: I didn't include support for base function names (e.g. > `"hello" |> strtoupper`) because of the conflict with constants. > Using a constant to store your function name is totes legit and > consistent with language syntax. > > Future Scope: Short Lambdas `$x => $x + 1` and Partial Functions > `someFunc('fixed val1', ..., 'fixed val2')` would help make this > functionality more useful and are worth discussing as a sub-thread, > but are not required to be implemented at the same time. > I think this feature makes very little sense if it's not introduced together with a way of making partial application much more ergonomic than it is now. I understand the desire to keep things separate, but I don't think that this proposal can land without partial application syntax being introduced beforehand or in conjunction with it. From a previous R11 discussion, I remember that two strong contenders were foo(...) for getting a callable with an arbitrary number of unbound parameters and foo($$) 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 single-parameter closures in compact form. Then you would also be able to write "$$->getFoo()" to get the equivalent of "function($x) { return $x->getFoo(); }" and similar. A disadvantage is that the precedence here is less clear and that a short closure syntax might be more clear for the cases that go beyond partial application. Regards, Nikita --001a113eccb61d477c05599c0e3e--