Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88609 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26395 invoked from network); 1 Oct 2015 16:28:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Oct 2015 16:28:14 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.179 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.212.179 mail-wi0-f179.google.com Received: from [209.85.212.179] ([209.85.212.179:38525] helo=mail-wi0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/00-26330-C1F5D065 for ; Thu, 01 Oct 2015 12:28:13 -0400 Received: by wiclk2 with SMTP id lk2so36507772wic.1 for ; Thu, 01 Oct 2015 09:28:09 -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; bh=TQgYUrjL5kpSwX1Ntrp6SrnvA7MK5hrzrSyjHGHORpA=; b=ss4sKkq4NfpGQ8K0lBJz2A8QliZu7vmg40e65nuS4CjmGBsU6scrmVLa//rQt0lmQf 6A5eMl5HR/+R3a6cEH0FDAcNfdmLmIzF8yzx6mWq4HYfzhnXshsZFJORrzhE0uFW/Fas JpDNN6nf3NCvz1ypotNkw2NPaM4vStz5BSuWd0+wqcpdM35cRacpm7PuKlwv99Gvvk1g 8lcqidJ61sb6Fd0Bn5S7LQFw5Q2cWpCXwlX3LrnOUYkC1iOyulqogkiyq9fcIuFap6VQ lbF7pPFl1S8mGtjBOGH9Y0tgCpE3aotYU2SPj5+u19wkb3XJTApOuRxiw4lmrHrPJCVx RDvg== MIME-Version: 1.0 X-Received: by 10.194.201.130 with SMTP id ka2mr11466381wjc.123.1443716889105; Thu, 01 Oct 2015 09:28:09 -0700 (PDT) Received: by 10.28.55.18 with HTTP; Thu, 1 Oct 2015 09:28:08 -0700 (PDT) In-Reply-To: References: <5606D0EB.3060106@gmail.com> <560D0F94.8060009@gmail.com> <560D282F.6060202@gmail.com> Date: Thu, 1 Oct 2015 12:28:08 -0400 Message-ID: To: Nikita Nefedov Cc: "internals@lists.php.net" , "rowan.collins@gmail.com" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Arrow function expressions in PHP From: ircmaxell@gmail.com (Anthony Ferrara) Nikita and all, On Thu, Oct 1, 2015 at 10:58 AM, Nikita Nefedov wrote: > On Thu, 01 Oct 2015 15:33:51 +0300, Rowan Collins > wrote: > >> That's not how Rasmus expressed it >> [http://marc.info/?l=php-internals&m=144107616411299&w=2]: >> >> > I made a very deliberate decision In the very first implementation of >> PHP to avoid scope side-effects like this. Inside a function everything is >> local unless explicitly declared not to be. This has carried through for the >> past 20+ years in slightly different ways, but the basic rule has stayed >> consistent even for closures. > > > Ok, it proves that it's not evolutionary that scopes aren't chained. Taking > my words back. > > >> It is a tool for making them shorter, yes, but it is not the only way, and >> it comes with a cost of changing established behaviour. Again, look at C++'s >> lambda syntax - it is much shorter than PHP's, but requires a list of all >> variables from the outer scope being captured. > > > C++11 doesn't *require* the list of all variables, but it does require > explicit "wildcard" ([=] for copy semantics, [&] for capturing by > reference). > But C++ is not the best place for picking up syntax choices, quite frankly > it's one of the least readable languages in a way that it allows you to > write very cryptic code easily (but still allows to write perfectly readable > code as well). > I'm not aware of reasons why ISOCPP decided that automatic capture should be > disabled by default, maybe it was because it was hard to decide whether it > should default to by-value or to by-reference semantics, or maybe [] tokens > were needed because of parsing limitations. > > >> You've picked on one syntax I explicitly labelled as "a straw man", and >> one idea which was proposed by somebody else a few hours ago, and use those >> to somehow dismiss the whole idea of a short syntax which lists captured >> variables. I have come up with about a dozen different ideas in various >> parts of this discussion, and could list dozens more. They would all have >> their pros and cons, but I don't see how you can dismiss the whole concept, >> UNLESS you consider the auto-capture to be an end in its own right, rather >> than "just a way of making it shorter". > > > I don't think there was a dozen of different ideas, I could only find those > about `lambda(arg-list; use-list; expression)` and variations of it with > different keywords and different return-type syntax. > I do understand that this is quite subjective, but neither this syntax nor > `fn(arg-list; use-list) expression` look obvious and easily readable to me. The problem is that semicolons are non-obvious, especially in a context where commas are used (and traditionally used). Example, tell the difference quickly between fn($a, $b; $c) => $a + $b + $c; and fn($a; $b, $c) => $a + $b + $c. At a glance, they are identical. You have to actually look at each item to realize that there's a difference. At least with use() there's a syntactical separator there to draw your eye to the contextually relevant information.