Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88506 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91051 invoked from network); 26 Sep 2015 07:06:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Sep 2015 07:06:23 -0000 Authentication-Results: pb1.pair.com header.from=pajousek@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=pajousek@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.174 as permitted sender) X-PHP-List-Original-Sender: pajousek@gmail.com X-Host-Fingerprint: 209.85.223.174 mail-io0-f174.google.com Received: from [209.85.223.174] ([209.85.223.174:36354] helo=mail-io0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 71/5A-31991-DE346065 for ; Sat, 26 Sep 2015 03:06:22 -0400 Received: by ioii196 with SMTP id i196so132182483ioi.3 for ; Sat, 26 Sep 2015 00:06:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=xFYO3JK+7rr1a3JcQ4+6YzS25qxAvbZx+qgrUmxNqzQ=; b=U15tHhJhcDA7+RfCk2iSOnxAgASUywyJaSuVNxFupii0fklGfKUudj7XZXo4Yko67H itokGS2VtTkKEoC2p1HxmVKDlJTk7ILp0HlklOBPS5ffvGM7PgKA7x2fECZW7QKc0GR7 ziFJW+YiucEYR1BRBViUyZ01yuUhoqaGIZXSEUQII4a6k3460dweinKWpuM8gNK79/6E /4FWzOZRHjsdaW3MOxZ7hs47MRcDh/L68+VqfMtl6UWkHh4xkAoXIDyeovF12txCT6iZ U8TOkFP+AVCsxfLmVOQdU+SUYLH9ibAzvib3SY7zxmFjBHIgsqph5W3qa916cDRdvbVz KiIg== MIME-Version: 1.0 X-Received: by 10.107.160.143 with SMTP id j137mr10377692ioe.13.1443251178874; Sat, 26 Sep 2015 00:06:18 -0700 (PDT) Received: by 10.107.189.132 with HTTP; Sat, 26 Sep 2015 00:06:18 -0700 (PDT) In-Reply-To: References: Date: Sat, 26 Sep 2015 09:06:18 +0200 Message-ID: To: bishop@php.net Cc: Bob Weinand , PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] [VOTE] Short Closures From: pajousek@gmail.com (=?UTF-8?Q?Pavel_Kou=C5=99il?=) On Fri, Sep 25, 2015 at 9:44 PM, Bishop Bettini wrote: > Hi, > > On Mon, Sep 21, 2015 at 9:59 PM, Bob Weinand wrote: > >> So, before I start the vote, just two quick notes: >> I've added two notes about the statement syntax and the single variable >> use. >> Though a few people complained, I'm not switching to the =3D=3D> operato= r, as >> I noticed many people expected typehints to work (they don't due to pars= er >> limitations) when they compared to Hack's short Closures. It also allows= us >> to differ syntax-wise [e.g. for typehints] from Hack without causing any >> confusion later. Which should be the smartest choice: Avoid conflicts. (= If >> anyone strongly feels against that, he may vote no, but I would like to = not >> bikeshed that in this Vote thread, but leave it free for eventual actual >> issues.) >> > > I voted "no" because I'm against the automatic use () and introducing a n= ew > symbol. > > An earlier short closure RFC [1] supports explicit import, and I would wa= nt > to see explicit import mandated. And rather than inventing a new symbol, > why not just re-purpose 'as' in this context? > > function sumEventScores($events, $scores) { > $types =3D array_map($event as $event['type'], $events); > return array_reduce($types, ($sum, $type) as $sum + $scores[$type]); > } > > 'use' is already purposed in three places, I don't see why 'as' can't als= o > be in three places. Though I've not checked the engine source to see the > actual effort, so this just may be astronaut architecting. > > Anyway, thanks to Bob for his hard work pulling this together and everyon= e > for arguing it out. That's what makes PHP great. > > Sincerely, > bishop > > [1]: https://wiki.php.net/rfc/short-syntax-for-anonymous-function Hello, I can't grasp the "intent" behind the "as". Reading it like "parameter $sum and parameter type as $sum + $scores[$type]" seems pretty confusing to me. Also, if we look at the example from RFC - with your "as" suggestion, it would look like this: function reduce(callable $fn) { return $initial as $input as { $accumulator =3D $initial; foreach ($input as $value) { $accumulator =3D $fn($accumulator, $value); } return $accumulator; }; } This doesn't seem like the right way to me. :( Regards Pavel Kou=C5=99il