Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88108 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51765 invoked from network); 7 Sep 2015 19:05:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2015 19:05: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 209.85.160.174 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.160.174 mail-yk0-f174.google.com Received: from [209.85.160.174] ([209.85.160.174:34053] helo=mail-yk0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E7/13-34134-DFFDDE55 for ; Mon, 07 Sep 2015 15:05:33 -0400 Received: by ykdg206 with SMTP id g206so88954797ykd.1 for ; Mon, 07 Sep 2015 12:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=aXbKIMw7ABBH6dAyujShU7I+gHKY00v2lti5MejX1VU=; b=SXXxRFhEhbjBSK8ToFT2ubNAkl5WinDIQiMs9YT2aGIL/isT+asywFcx8mO2DwFtNv iZ+Arc8Gc2BVvcvlXsS91N9RtNi3E3rabrTeke6RkEjbzFt4l442j4m/HF33sW8A6Yau zXVH3P86ZeVBSjXn10m6SaGebax3BeO+wxZ3Uo/3lKDiITtfspouEpRsfJCMNujuQTqO 4uSsAN316I8aKkHU67LvFV5HzUZTERGrImo1jugaO09DW4giSRAPJOYpNv8Yggnmt2Rw akOwI93nYjkQdSh0csVHHQFIjVogGvOnTDQDVNZPYB+sqnZ/4PLsasK9c4y3cdimJFZ8 sskw== MIME-Version: 1.0 X-Received: by 10.170.127.203 with SMTP id t194mr21921174ykb.41.1441652729703; Mon, 07 Sep 2015 12:05:29 -0700 (PDT) Sender: morrison.levi@gmail.com Received: by 10.31.41.205 with HTTP; Mon, 7 Sep 2015 12:05:29 -0700 (PDT) In-Reply-To: <8E.91.34134.B57DDE55@pb1.pair.com> References: <55E77CA9.7050609@gmail.com> <55E81959.6040305@gmail.com> <55ED817B.5030109@gmail.com> <8E.91.34134.B57DDE55@pb1.pair.com> Date: Mon, 7 Sep 2015 13:05:29 -0600 X-Google-Sender-Auth: Gwi6-9PyImHrnk2iHoYLiBaXGqg Message-ID: To: Andrea Faulds Cc: internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] [Discussion] Short Closures From: levim@php.net (Levi Morrison) > I think a possible improvement might be a generalised syntax, similar to > that used for constants, that lets you use any \Closure object to define a > function or method. Thus: > > function reduce = $initial ~> $fn ~> $input ~> { > // ... > }; I like this but we're getting a bit too far in the future RFC territory. But bringing this back to the current proposal I think that the curly brace syntax should stay. I much prefer this: function reduce = $initial ~> $fn ~> $input ~> { $accumulator = $initial; foreach ($input as $value) { $accumulator = $fn($accumulator, $value); } return $accumulator; }; To this: function reduce = $initial ~> $fn ~> function($input) use($initial, $fn) { $accumulator = $initial; foreach ($input as $value) { $accumulator = $fn($accumulator, $value); } return $accumulator; }; So while assigning the result to a named function (instead of a variable) is out of scope of this RFC I think it demonstrates the value of the block syntax which I think we should keep. I've said this several times now, so I won't say it again :) > This has that advantage that it isn't just useful for when you want to use > the short syntax. You can also use it when you're obtaining a Closure in > some novel way, perhaps a higher-order function: > > // where "add" is a function that adds two numbers > function sum = reduce(0)("add"); > > With this, you don't have to write a wrapper function, or use a global > variable, to define a proper top-level function. I like this as well but again we're getting a bit too far away from the current proposal.