Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88102 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38240 invoked from network); 7 Sep 2015 17:31:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2015 17:31:27 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.178 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.178 mail-wi0-f178.google.com Received: from [209.85.212.178] ([209.85.212.178:33139] helo=mail-wi0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 43/C0-34134-EE9CDE55 for ; Mon, 07 Sep 2015 13:31:26 -0400 Received: by wiclk2 with SMTP id lk2so95364902wic.0 for ; Mon, 07 Sep 2015 10:31:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=5uaBhHnLzJ8AjZCx0mySFU6v6bQsbu3gZLRpt4jQGaI=; b=aYdAaxJHN9s6yd1GEmVk+jle6wQ2NbanlnS4ZKLPbFSV3v3IuSfBX7BaUUbafU7YTC CwUvb6xI/tbZJQtID3D37l3nrDF3mGzkBNZwtAX/miZN6MKd08qtiUUV5Wxz7+TCn9gO 7ia/XMil+ORH/4jaxpAaxA/eL4nCLd8oSgD4aTOftMIJcxuBOKuG9Gw+9oKFvtLA/n6n uomXe9BmJAdL6JNpgkRUkx6u0Sa2qXx1bXc4bt+UrcCltdZ/ggKwp09jfWqA2R00NRWs CRWS5moH0boVEiTRcu0s2FjYR2h9MuoFQGkmCcqUAyXw9qWVlG0+L65K/EdwmrX1N+vI t/+g== X-Received: by 10.194.174.133 with SMTP id bs5mr37371026wjc.156.1441647083849; Mon, 07 Sep 2015 10:31:23 -0700 (PDT) Received: from [192.168.0.134] ([62.189.198.114]) by smtp.googlemail.com with ESMTPSA id p3sm460635wib.16.2015.09.07.10.31.23 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 07 Sep 2015 10:31:23 -0700 (PDT) To: Levi Morrison References: <55E77CA9.7050609@gmail.com> <55E81959.6040305@gmail.com> <55ED817B.5030109@gmail.com> Cc: internals Message-ID: <55EDC9AF.9020408@gmail.com> Date: Mon, 7 Sep 2015 18:30:23 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.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] [Discussion] Short Closures From: rowan.collins@gmail.com (Rowan Collins) Levi Morrison wrote on 07/09/2015 17:56: > function reduce ($initial) ~> $fn ~> $input ~> { > $accumulator = $initial; > foreach ($input as $value) { > $accumulator = $fn($accumulator, $value); > } > return $accumulator; > } Hm, this is an interesting idea. I actually think the case for it is *stronger* if ~> was considered special syntax for trivial functions, because if not, there's this odd hybrid, which we probably wouldn't want to allow: function weird_declaration($bar) ~> { any(); code(); here(); } Whereas this declaration might be quite useful: function double($x) ~> $x * 2; I realise the syntax was only an example, but this way there'd be a nice consistency between named and anonymous functions. I think that would leave your example as: function reduce ($initial) ~> $fn ~> function($input) use ( $initial, $fn) { $accumulator = $initial; foreach ($input as $value) { $accumulator = $fn($accumulator, $value); } return $accumulator; } Regards, -- Rowan Collins [IMSoP]