Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88606 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16197 invoked from network); 1 Oct 2015 14:58:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Oct 2015 14:58:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.177 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.217.177 mail-lb0-f177.google.com Received: from [209.85.217.177] ([209.85.217.177:35213] helo=mail-lb0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4D/47-04700-A1A4D065 for ; Thu, 01 Oct 2015 10:58:35 -0400 Received: by lbwr8 with SMTP id r8so10879513lbw.2 for ; Thu, 01 Oct 2015 07:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:to:subject:references:date:cc:mime-version :content-transfer-encoding:from:message-id:in-reply-to:user-agent; bh=E9PX9e6W4ZNEEkzmBDHH9jvCOdD0ApEzu4Ij5lrQ3hQ=; b=sM5CEh9wmxoLEVIV1FKsf6PoDI5dFx4Hal8mD1ecZZwM7I+MmLLaFdoB0u9MOSOnvO SEcw54tNMS4O3iHSRFn+67Jq+c33tkDRDR4uH37pKAAqEqVCKeeuOb2N7RoX+MMrJFB1 xTLu/IpD0lfCR+Vr+8qNUWzJgg70ydnQeoG1LJp7dhWnI7GmDwn/Ei/4IPgpkZ33zwOB eghCrzGnYH/Hi9z9HqyP5BymOypIsVbLqMZp6JbfwQFC4LeUJYa8Wm3iZDfOr2JNyZwT r8V+Yj4O3krYpvcqCHPfpqbxbPYvsK9gKpHFuW0NuF/X/fGjtE61V/v8CfGEIdJQl2qc rOAA== X-Received: by 10.25.24.101 with SMTP id o98mr1964523lfi.24.1443711511824; Thu, 01 Oct 2015 07:58:31 -0700 (PDT) Received: from nikita-300e4c-300e5c-300e7c ([185.62.192.230]) by smtp.gmail.com with ESMTPSA id up2sm691689lbb.23.2015.10.01.07.58.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 01 Oct 2015 07:58:29 -0700 (PDT) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <5606D0EB.3060106@gmail.com> <560D0F94.8060009@gmail.com> <560D282F.6060202@gmail.com> Date: Thu, 01 Oct 2015 17:58:28 +0300 Cc: "rowan.collins@gmail.com" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: <560D282F.6060202@gmail.com> User-Agent: Opera Mail/12.16 (Linux) Subject: Re: [PHP-DEV] Arrow function expressions in PHP From: inefedor@gmail.com ("Nikita Nefedov") 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. And one thing that makes auto capture much better choice than explicit capture (as it've been said a couple of times already) is partial application: $mul = fn($x) => fn($y) => fn($z) => $x * $y * $z; Looks simpler than: $mul = fn($x) => fn($y; $x) => fn($z; $x, $y) => $x * $y * $z;