Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51074 invoked from network); 17 May 2016 23:10:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 May 2016 23:10:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wm0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:38060] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 00/B5-11000-0D4AB375 for ; Tue, 17 May 2016 19:10:08 -0400 Received: by mail-wm0-f42.google.com with SMTP id g17so53895197wme.1 for ; Tue, 17 May 2016 16:10:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=OGFmZRmIzENHfveYrHY6/TaOxZCTY/wbAtvD9SBUWRg=; b=Vaq3Xq2ACuEo6dN/4GdXfRjq9l9qZzpcVV+Z9ANDoqC5wr3qL285O05rZjWdbPb25Y Kfwv71DE3f1x1vayymblkgASbKyReshSTGrCdM+B0z57uxPz62VBcP2nakLmmOGTAyvT 0tZuOuYSWEDeaWlOdEe4+gFYWcxYOP0ClZISWyuQiQP3lokVdF4b9bAJryoENWpFSXW4 cV+LeqNcDRWsy592KA2XNx0iRjMftYQonud/ilI8U3MbBMFH1zPXU0bUOYP1nuZ5cVUu WnTQjKjw3Phgg6ILGVnzEi8oHdTw9Mwn9ei59/1KL4r8AMcqYE1ihFOECxRmvfuLaWcL aH1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=OGFmZRmIzENHfveYrHY6/TaOxZCTY/wbAtvD9SBUWRg=; b=k6iXCXwoKkJQeK71e9wOVBpyRdrE/pQqj0iwVxALXHfm0ImwHkh3Eb0JM1m8bF9DWj M6zLZdOwh7yu3eRaspSBUACeam8sVnspS6HIOnKJvlRcxSwRYDI9ai9rw57YWEbAwR/J 1Ll+dvRsSs9ltmsYsjKQPSGXyFp9J4dUyDrDF3XWFrZqeKeHBZp/0qOrJK3Dl1GtsUqs 9OnjpVGF8j/BSqDZeBF+NkiR8+B8jhPQRp9X9dIkgauN0vUaZv8eggex88D6KuTqRQaP pQo3RtutZCucbIYTaxjZ4Czz/8e4K0+sLtJQPzIgUu/2I7krqvbK0GUT3mIKkyDSanX7 Xk/Q== X-Gm-Message-State: AOPr4FWzipCaHdoxoF3onZfNw/aLyco5PL27QwP3gx3IU3a7tvHrPPO5I6oVfUAehu+G/Q== X-Received: by 10.28.145.73 with SMTP id t70mr25104647wmd.97.1463526605594; Tue, 17 May 2016 16:10:05 -0700 (PDT) Received: from [192.168.1.189] ([2.27.88.132]) by smtp.googlemail.com with ESMTPSA id f11sm26482768wmf.22.2016.05.17.16.10.04 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 May 2016 16:10:04 -0700 (PDT) To: PHP internals References: <66d7fe0f-6c0b-c6c0-f30a-a54ccd10e949@gmail.com> Message-ID: Date: Wed, 18 May 2016 00:09:59 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Pipe Operator From: rowan.collins@gmail.com (Rowan Collins) On 17/05/2016 18:46, Sara Golemon wrote: > On Tue, May 17, 2016 at 4:14 AM, Rowan Collins > wrote: >> On 17/05/2016 11:55, Jesse Schalken wrote: $id |> >> StringList::decode($$) |> array_replace($$, $replace) |> >> StringList::encode($$) |> $id; >> >> >> Sara, what do you think of this tweak, and my subsequent suggestion >> that the pipe should only be usable as a *statement*, not an >> *expression*? >> > I'm not strictly against it, but I'm not a huge fan. Primarily, > it's the statement-only restriction that bothers me since (apart > from control flow structures), most constructs in PHP are > expressions, not statements, and this feature naturally fits in the > composable expressions category, not the top-level statement > category. A perfectly reasonable position. I guess my counter-argument would be that this is a kind of control flow, a "do-this and-then do-this". But mostly the suggestion to restrict was to have one right way of laying things out, rather than allowing people to make it even harder to follow by mixing nesting with pipes, for instance. > From an implementation standpoint, I'm fairly confident that the > patch would be much more complex as a result of enforcing that > statement-only requirement. Ah, I did wonder if that would be the case, and I don't think it would be worth pushing in that complexity. > Meanwhile, if we remove the statement-only requirement, then using > "simple-variable" as a signal to switch to expression termination, > then we introduce a whole class of bug where a user fat-fingers the > $$ token in what SHOULD be another link in a chain expression, but > it's not detectable as an error because a simple-var is valid. > > And one more counter-example: > > $x |> foo($$) |> $y[$$]; My original suggestion was to have a different token for the terminating assignment, such as "|=>" (looks a bit prettier than "|>="). That would get rid of any such ambiguity. If we keep the pipe as an expression, I guess the assignment can return its value like a plain "=" would; so: $foo |> operation($$) |=> $foo; would be extra sugar for: $foo |> operation($$) |> $foo = $$; Incidentally, the RFC would benefit from a couple of examples of using something other than a function call as the RHS of the "|> " And you could even use it mid-pipe, as a kind of "tee": buildRequest() // (basically the first part of the previous example here) |> validate($$) |> convertToCommand($$) |=> $command |> execute($$) |> convertToViewModel($$) |> render($$) |> convertToHttpResponse($$) |> emit($$) |=> $response; $command |> censorCommand($$) |> logEvent($$); The other special case that's trickier to incorporate if the pipe acts as an expression is returning from a function. I presume "return $$" would be an error, unless it's given special status, which is a shame... scandir($arg) |> array_filter($$, function($x) { return $x !== '.' && $x != '..'; }) |> array_map(function ($x) use ($arg) { return $arg . '/' . $x; }, $$) |> getFileArg($$) |> array_merge($ret, $$) |> return $$ You mention in the RFC that the source of the data going through the chain is "clear and unambiguous"; I think it would be great if the *destination* of the data were equally clear. For instance, a subtle edit to your example: ($ret = scandir($arg) |> array_filter($$, function($x) { return $x !== '.' && $x != '..'; }) |> array_map(function ($x) use ($arg) { return $arg . '/' . $x; }, $$)) |> getFileArg($$) |> array_merge($ret, $$) |> $output->append($$); At a glance, what would you expect in $ret after that code runs? I guess this falls close to the "stopping people writing horrible code" fallacy, but what I'm interested in is what the good code should look like: scandir($arg) |> array_filter($$, function($x) { return $x !== '.' && $x != '..'; }) |> array_map(function ($x) use ($arg) { return $arg . '/' . $x; }, $$) |=> $ret |> getFileArg($$) |> array_merge($ret, $$) |> $output->append($$); Regards, -- Rowan Collins [IMSoP]