Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88016 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19728 invoked from network); 2 Sep 2015 22:48:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2015 22:48:29 -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 209.85.212.171 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.171 mail-wi0-f171.google.com Received: from [209.85.212.171] ([209.85.212.171:34346] helo=mail-wi0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/61-10015-CBC77E55 for ; Wed, 02 Sep 2015 18:48:28 -0400 Received: by wicfx3 with SMTP id fx3so1685276wic.1 for ; Wed, 02 Sep 2015 15:48:24 -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-type:content-transfer-encoding; bh=xQv8Zt+FGpZV3Z9/FLORAaFPfiU7UQ+oe8qTl6JxzpM=; b=T605W00sLVWnvxklsAYcHQcl1HNd0vKZcHbPaU6MQmeopjoVBunJg8bzvXaIbSja7k /4KG7dL54dGlDtq1SogfEj42m2QNMK6fJ12/WsZ5JERIW0E3y/S7aIej/odcDGkVWnbm zvYXzplmydESoGlXvUM7odl+Va0xYzT/7Q4ES9QfmmXP1ZB9wW1Blutmb7iCJkmtds+t zSWEmP075653kWOvbU/FaXKDxA0J000nLI9Bg3Y2MguJMIbLGG9duUSIz83kQcyTtM1C U8iGF8MWrCXmDiQgbBSOVhov+RibaNno8rVE2oBX69d3G8h/A0aPVnKzxGgWn9uPdZuo fWqA== X-Received: by 10.180.72.230 with SMTP id g6mr7798380wiv.79.1441234104756; Wed, 02 Sep 2015 15:48:24 -0700 (PDT) Received: from [192.168.0.5] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by smtp.googlemail.com with ESMTPSA id c7sm34585151wjb.19.2015.09.02.15.48.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Sep 2015 15:48:24 -0700 (PDT) To: internals@lists.php.net References: Message-ID: <55E77CA9.7050609@gmail.com> Date: Wed, 2 Sep 2015 23:48:09 +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) On 02/09/2015 22:49, Sara Golemon wrote: > Beautiful code is code that is easier to > maintain, and code that is easier to maintain is often more secure and > reliable. I think this is an important point. Obviously, "beauty" is subjective: some people will find very verbose, English-like code easier to read; others might try to squeeze as much information into one screenful as possible, so they can see the whole program at a glance. At one extreme, SQL has mandatory words like the "AS" in "CAST(x AS int)" just to "look more like English"; at the other, APL has symbols all of its own with their own Unicode code points. Most languages aim for some compromise in between. So I would like to put forward for consideration these amendments to the proposal, in the spirit of compromise (in no particular order; numbers are just for reference in future discussion): Amendment 1. Only allow the single-expression form of the short syntax; full function bodies must be declared with the existing function(){ ... } syntax. This gives a clearer distinction between how the two syntaxes can be used. Amendment 2. Make the ~> operator non-associative, so that lambdas returning lambdas would need an extra pair of brackets making the nesting explicit. To take one of Anthony's examples: function partial(callable $cb) { return $left ~> ( $right ~> $cb($left, $right) ); } It's now at least clearer that there are two different anonymous functions here, even if it's not entirely clear what they're trying to achieve... Amendment 3. Make the parentheses around the argument list mandatory so that (if Amendment 1 is also adopted) there is only a single variant of the syntax, namely "( param list ) ~> expression". Amendment 4. Consider a syntax involving an explicit "use". This one requires a bit more exploration, but maybe something like: ( $a use $b ) ~> $a + $b or: ( $a ) use ( $b ) ~> $a + $b Perhaps there are other thoughts along these lines that could move the proposal beyond a simple love/hate debate. Regards, -- Rowan Collins [IMSoP]