Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100742 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87557 invoked from network); 21 Sep 2017 23:06:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Sep 2017 23:06:35 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.52 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 74.125.82.52 mail-wm0-f52.google.com Received: from [74.125.82.52] ([74.125.82.52:47815] helo=mail-wm0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/18-62331-9F544C95 for ; Thu, 21 Sep 2017 19:06:34 -0400 Received: by mail-wm0-f52.google.com with SMTP id r136so5712840wmf.2 for ; Thu, 21 Sep 2017 16:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=FNKBdsgQMRGSxaYYXF+gGuSISi0r0OMxsrFRrtGyClA=; b=m6h1bHiDWjH7DZuJ5zz/T6oWH6tMIbQZpuerj13JidHVbiN+h8MEECgSXvHUcM3A71 tcvNwbQlcODg6jfFK2Vsw+LWsBrO0EprtEZ7NFTHKiDYuwV7RetRSI9goE63Q4m5Vs8d Cf9MmxQZQ9f6aO5dbb43Mqti2ctnQL4/Bz0T8rj16uRHfIbtgkvKn132KqJg4jG20rl4 SvAK6VAlkx5m6bkMsuTNdaef9JW0VgB0GjoEeoxbBDE7MjbYfOKkA5MRLjjd6tVBPOFj j8ngonBv7kAQEGUZOTSMl6J8bM+98hxLJlXhZPRb5kOinfxwUm8tx4r92aJ6Ri0OkYdZ KcUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=FNKBdsgQMRGSxaYYXF+gGuSISi0r0OMxsrFRrtGyClA=; b=dlox4cpGS+bDDOqOpzkIRZFM0vH4TJ1DGcTYpDWBM5rj2ZxpxDEgeEYNOdLJUl4TQ4 pJkuT2syyyiVPfmSH4yiRiuulQSuLNiKznXhjz+R9J5C9aBDDLM4pAsZdojGDsakTfTi DQKrkgUY3FMuXslvqNZqyI0vtufMU34ZKuFhI9Nnga/x1L5iRsEV6VTCrGFTjoyW+mW8 Od1O4a3+Tsmka0yJ6+u4vu+0iUfChlUGBTSb1NS8yQJ/TpDJi9AxvpYDR1Q8ZYS0C56P BjpEzXf3sM2Nzaqg8WBd5q2b2ts0jLeJ9iiGMq4eUzzRZItIqgHx10Q2IPNDReYOsNDl qP1A== X-Gm-Message-State: AHPjjUgN4JLgJ8XlVgTG7KGyjofshA6FLsat6RQTZwOsRPnl+2FJjRHu j2Cq/b4AlZRBc2FrgZsakCR3l82N00JAZ1gD0LuJroLJ X-Google-Smtp-Source: AOwi7QBH7i1oMuPZdi/9PNTCAd8qjd8C6FCAG9NM0Sh696YrIsRROslSs/JgjMtZAzNfoqTtYX6YozI9q+PwBY01+zc= X-Received: by 10.28.164.68 with SMTP id n65mr2106917wme.23.1506035190927; Thu, 21 Sep 2017 16:06:30 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.28.193.130 with HTTP; Thu, 21 Sep 2017 16:06:30 -0700 (PDT) In-Reply-To: <98e7fff2-72ac-0430-72bb-099a021626f6@gmail.com> References: <98e7fff2-72ac-0430-72bb-099a021626f6@gmail.com> Date: Thu, 21 Sep 2017 17:06:30 -0600 X-Google-Sender-Auth: uO-qm6QpnKS26ZtmvTiUOk5ANBc Message-ID: To: Stanislav Malyshev Cc: Sara Golemon , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Pre-draft for PipeOp v2 From: levim@php.net (Levi Morrison) On Thu, Sep 21, 2017 at 3:13 PM, Stanislav Malyshev wrote: > Hi! > >> 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. > > I am still feeling it is a bit weird to do things that way, but other > than that (which is just my personal issue) I do not see any problems in > this proposal. With magic weird $$ thing gone, it seems to be > straightforward and mostly intuitive. So while I am not feeling this is > a must, I think it may be nice to have it. > > It'd be also nice then if we could have some syntax that allowed us to > refer to functions/methods as callables - mostly for the benefit of the > 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 do > something like this: > "hello" |> &{strtoupper} > "hello" |> &{$this->bar} > > (yes I know the syntax is ugly, I hope you get the idea though to have a > syntax for this) then you could have better readability, easier IDE > autocompletion and other benefits. Not for this RFC, clearly, but just > putting it out there so I don't forget. > > -- > Stas Malyshev > smalyshev@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php I don't want to get too far off topic but since Stas has wandered off a bit already I'll mention this. Scala has "placeholders": val sum = List(1,2,3,4,5).reduceLeft(_+_) The expression `_ + _` will create a function that takes two parameters and then returns the result of adding them together, equivalent to this: val sum = List(1,2,3,4,5).reduceLeft((a, b) => a + b) The single underscore `_` might not work for PHP because `gettext` has used a single underscore as an alias for... a long time, maybe since its inception. But for this example I'll use it anyway: "hello" |> strtoupper(_) |> $this->bar(_) It's saying, pretty literally, fill in the blank. Remember, though, it's actually creating closures and doesn't directly mean "put the result of the left-hand side here" unlike the previous proposal for `$$`. I brought it up because this can fill the same need as Stas' proposal creating callables with something like `&{strtoupper}`. If we used the symbol `$$` for the same placeholder mechanism from Scala it becomes a more general purpose mechanism that could be used for any callables, not just ones involved in a pipe: $potentially_valid_emails = array_filter($this->isProperlyFormattedEmailAddress($$), $email_list); Anyway, the purpose of this thread is to talk about the pipe operator so I'll stop talking now.