Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98206 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 88124 invoked from network); 5 Feb 2017 11:11:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2017 11:11:00 -0000 Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.220.195 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.220.195 mail-qk0-f195.google.com Received: from [209.85.220.195] ([209.85.220.195:36380] helo=mail-qk0-f195.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/9D-38491-24807985 for ; Sun, 05 Feb 2017 06:10:59 -0500 Received: by mail-qk0-f195.google.com with SMTP id i34so4782017qkh.3 for ; Sun, 05 Feb 2017 03:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=D9c9o/5k+GJBJq21a3KZn66xk8RxGegy80oE0Xh7Emw=; b=w88AZEzgSgWLoPZe3uQE/XO+uq5wnPnFunTHijWKz7uv7cBMb+1+XRBGLJdB8vrp5v UG8SA+JwRx0EazGrhaF4ZZjULho/Grsjz2e+YVEpC+bmzA/d/mpr5z/qhmx11sGve06K zvHTLWsBXBEnPnHQZvIexutwAIpDqoYSLjnzg3AY1Xx0m7DLkVzjnUWL8UUmO3jKroKp TIfIDsdjrrAinsW1lvSI4zSQb7JyTH7Ly6y+Ofa0INLJg5R0BzrG1vKxoNjai3fz54Yi GZWqqhYa1fK0wZMs8RtvmdBUa1I8+hCF7nf/SqhvVI7ix+YrsYRGQar2GKMowrB9HgG/ RsAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=D9c9o/5k+GJBJq21a3KZn66xk8RxGegy80oE0Xh7Emw=; b=ZGvnUSh3TyDAZN9AEAAxNSY9uoJXlzMgLoNjCgzdDUSG5ZyL+8uZU4UYa/CyPaFHeh 88HInCaNLNhm3v+Qw7SSHFc7G9nc93fpBVD7exILYirBOTTJnfjFaIbCfgeh8t/O6ae0 Lz/RUSoYdQH3UN2RfS3EHeO//Vja3utGGjokdzFOAkARma4qyD5kvI8ayV2R4r0unRgf aSc9Imh+rqDkVZfoh9uTZGkMJi173hgkcs1U9xAUl2czhgHrsBlzN+wufelsBTjJydxh iiuNEazBwZsmNtC21A+Vt5qLa3EkKYucd20UcxCruIBRIsDQ9a/qwm0c1bncV5r9bvAc kT4Q== X-Gm-Message-State: AMke39n+U3eSRN1uftQvMKRl86z0Z3eFIuhpsg+4hlBE2JzCDItwq0w5cBlVjdssdSggBjcO9NEtZPI7cKMAaA== X-Received: by 10.55.190.129 with SMTP id o123mr5580926qkf.110.1486293056134; Sun, 05 Feb 2017 03:10:56 -0800 (PST) MIME-Version: 1.0 Received: by 10.237.47.231 with HTTP; Sun, 5 Feb 2017 03:10:55 -0800 (PST) In-Reply-To: References: Date: Sun, 5 Feb 2017 12:10:55 +0100 Message-ID: To: Levi Morrison Cc: internals Content-Type: multipart/alternative; boundary=94eb2c043994a4cae10547c691fa Subject: Re: [PHP-DEV] [RFC][Discuss] Arrow Functions From: rasmus@mindplay.dk (Rasmus Schultz) --94eb2c043994a4cae10547c691fa Content-Type: text/plain; charset=UTF-8 I'd strongly prefer a syntax without the introduction of "fn" keyword - e.g. similar to closures in other languages. I also feel that there's a feature missing - something that was possible with closures: $total = 0; $add = function ($value) use (&$total) { $total += $value; }; Per the RFC: > When a variable in the expression is defined in the parent scope it will be captured implicitly by-value Whether you regard it as a good thing or bad thing (I'm only pointing it out) this is inconsistent with JavaScript, where variables in the parent scope are captured by-reference. If we're introducing a new form and syntax for closures, why not make this one align with something that's going to be familiar with developers? That's just my opinion, but whether you agree with that or not - as long as we're introducing a new form and syntax, why make it *less* capable than ordinary PHP closures? At the very least, I feel there should be feature parity - otherwise, code in the wild is going to continue to be a strange mess of one form or the other, which doesn't help with language comprehension at all, especially when both forms also work differently from JavaScript closures, which are likely the form of closures that web-developers are going to be most familiar with. Don't get me wrong, I'm not saying "make it like JavaScript" - what I'm saying is, make something that is familiar to developers *somehow*, e.g. either provide feature parity with ordinary PHP closures and make it familiar to PHP developers, *or* make it similar to JavaScript closures, but don't throw yet another "original" idea on the pile. Ultimately, I think what I'd like to see would be something along the lines of this: $total = 0; $add = ($value) => { &$total += $value; }; That is: - Lose the fn keyword - get the syntax down to something similar to closures in most other languages. - Keep it working like PHP (which you intend to do anyhow) in terms of importing variables by-value. - Provide feature parity with regular PHP closures by providing some means of accessing variables by-reference. I understand that the fn keyword is there to remove ambiguities, but I think working around the ambiguities is possible, even if it's difficult - there was ambiguity with < and > operators in the run-of-the-mill generics syntax I proposed last year, and Dominic Grostate was able to work through them and get it to parse after all. I understand it's probably difficult, and it may not be possible to achieve something that is 100% technically correct, but it's usually possible to achieve something that works for almost any real-world use-case. The last thing I would comment on is multi-statement bodies. Omitting this is, in my opinion, a very bad decision - it will, again, lead to lack of feature parity with regular closures, which will mean, in practice, factoring back and forth between regular closures and fat arrow functions, which will be frustrating. It will also encourage developers to attempt to fold complex operations into a single expression, leading to further frustration for the programmer, and unreadable code for collaborators, because "damnit I'm not going back to regular closures!", right? In my opinion, if you can't provide feature parity on these points with regular closures, this feature will hurt more than help - it will lead to a lot of meaningless struggles, unreadable code, and code that doesn't refactor well, and, eventually, BC breaks when PHP 7.x finally does introduce these missing features. On Mon, Jan 30, 2017 at 6:55 PM, Levi Morrison wrote: > Bob Weinand and I are happy to announce that the [Arrow Functions][1] > RFC is moving into the public discussion phase. We have been > collaborating on this RFC for many months now and finally have a > proposal we are happy to discuss in the open. > > Here is an example of an existing closure: > > function ($x) use ($arr) { > return $arr[$x]; > } > > This RFC proposes syntax and semantics to simplify this common usage to: > > fn($x) => $arr[$x] > > More details are in the RFC. The [implementation][2] currently has no > known issues and is ready for you to download, build and test, which > we encourage you to do. > > We look forward to a productive discussion period and are happy to > answer questions. > > For historical purposes, the revision of this RFC is currently at > [1485798604][3]. > > [1]: https://wiki.php.net/rfc/arrow_functions > [2]: https://github.com/morrisonlevi/php-src/tree/arrow_functions > [3]: https://wiki.php.net/rfc/arrow_functions?rev=1485798604 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --94eb2c043994a4cae10547c691fa--