Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100799 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20985 invoked from network); 29 Sep 2017 12:24:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Sep 2017 12:24:28 -0000 Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.15 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.15 mout.gmx.net Received: from [212.227.15.15] ([212.227.15.15:64510] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 10/A1-34435-97B3EC95 for ; Fri, 29 Sep 2017 08:24:26 -0400 Received: from [192.168.2.106] ([79.243.124.218]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MKHtm-1dwGB92sLe-001fok; Fri, 29 Sep 2017 14:24:22 +0200 To: Sara Golemon , PHP internals References: Message-ID: <6a857d65-91d7-aba6-0be0-e9c424e34cc3@gmx.de> Date: Fri, 29 Sep 2017 14:24:22 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:JcYX31LtBdHgWExATgEW1BQpjaqrkzZsoIQBUWrqp2TXnlf7vcg Gej4tgbKQOWBUFZBW7xYxzvfGee2v/b3A1gfU7Ek96bYbi2hcwPjIeoJOeD9S52oEYPVHOG laEt0a+K/auFx0/C1i2kKI4fZfRzVKFPQFaQjijZ7MFULex4Ly3EHYhfBWxCaq01dJG05kv DLi2+DBqOjl8vNlcKVMHQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:T4gBzFVVmhg=:H56P5wjoVe+CmMRUye46Os h9nZwIbjAOWiFYSTZAJjeW68KfbAc5cxGVx3i5X9yWOuiIJlYG8qqoKL5q2JYfcXgfj2odMR2 8IB9iQSl8Sk/qEOvULFZdT2VYx+UL+zx1ju0hR7SkJbrhWkduhOWxZcL7Zj7CkvpZkiihrwdq O+YT0S3FqXokVc0VQVF/czJ6b0J9eQDwjh1f+bpbnOMhl55eaXzlttBYiDVfMb+jpdssNATho vh/qM6DBAQ0QccR3KIH8lz3oe+zmbwbRYNl3xyvzy6Nmx00Y0c2WAhFko6vNkZoDrxODkuoPv I0e3TOMRMneQ4enhHai/DBaUCGhRUW3r41Wv1HMyA4UzPuZ8owwU9XCZyKeROtV7FOas/BDSV qYM025dE5nA5tbuT51deaMrWihHUWilEx7QnPQRUXscLyaViVExnA3knotLQnPaYKxtbEW0hT 88T+N5BV2q/bfJ5nbqGzfIwXcHrTFURdht3wrC4xdf2DMzfRiDv3jAM8nX1F6IKVJ5yAgH/NJ toyEw3isyXysM5tAU6Nehq6U9pkdwGR2S2XWf0qETX3dCKgK9iJ1XgElry1FpGPCZMS+xSlrU ikf9MS9wYWLM615CUAD17RHrn5zo7nezCiXEdm9sDJ019FDEU9ZqMf4zuLmKKtxnMAzA6zm22 lxHlv3bybbSa5l45wZlO3XMpxMdN7VqPpqqWTs2H9Zb3+9IhxXhNYnj+zKQa+4C2kViJkRBRy Cn4kp189LUfCNJ9RaRQvt1Q80vTQh+2nhWyrEtpDYWL/CrFM5xa38JOuo2Lh9XjU4Devur4AY Vr5Z3cnO0NLnSVeoiFBJ7SkVw62HPjrH5m9qpvGTlV5a9YPKFQ= Subject: Re: [RFC] Pre-draft for PipeOp v2 From: cmbecker69@gmx.de ("Christoph M. Becker") On 20.09.2017 at 00:32, 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. I'm not particularly fond of a pipe(line) operator. I don't see a great advantage over a simple compose function: $appendWorld = function ($x) {return "$x world";}; $x = compose('strtoupper', $appendWorld)('hello'); The benefit of using a compose function would be the possibility of point-free programming without explicitely declaring another function: $toUpperAppendWorld = compose( 'strtoupper', function ($x) {return "$x world";} ); $x = $toUpperAppendWorld('hello'); $y = $toUpperAppendWorld('goodbye'); Basically, the compose function would be like the pipe operator without special casing the (first) input. See also Andreas's suggestion regarding built-in functions for common functional primitives (). -- Christoph M. Becker