Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99271 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56242 invoked from network); 30 May 2017 17:58:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 May 2017 17:58:19 -0000 Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.51 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.214.51 mail-it0-f51.google.com Received: from [209.85.214.51] ([209.85.214.51:34543] helo=mail-it0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 64/C1-43873-9B2BD295 for ; Tue, 30 May 2017 13:58:18 -0400 Received: by mail-it0-f51.google.com with SMTP id a10so11261966itg.1 for ; Tue, 30 May 2017 10:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to; bh=jBKHe5wZwyclzTQgGvVnAIWw75dgn/XMgtGI831vsmQ=; b=pA7qM0UQm7DZXKWfUQ93bD0MpTE7F2+vkFd4jMxMZixUre/OKn8z/LzVllbIcJrQZr jpY/UOYb1QoevY/Ob8dNaTGip/DyacAfG1sy7atQb4r+22uhS//DXfs23ifLu6P9keNE Tykyw7Hf4miFI/XuUB0DQQevAfxcCBjd7IltfUA5002qunOz6hovYa8TaFJB6TNNSchw 1I/wfZV0UC/YirIyoQMYC5cXgQ+qbWwsnHJpFF85aNSy/ZD6OUUgbNYq6crAHT01TiEk lZ4Gvbi2TRz72j77hFgErPuLaf9V5mmWFr5OayJ0Rs8/0vtE+mA5wx6wddXFbVmt7glm hsYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=jBKHe5wZwyclzTQgGvVnAIWw75dgn/XMgtGI831vsmQ=; b=bn3QO6RWowqg/0Rg449baHXJGnSITlxzvOi5q1y7HqECkqFy6kSImaXSc+HlxIDLV1 Nuxd5Paz/ijWw3AxGitMVXrGwc0OdJaTcXr13Ip2sgzi02ia6XZYayV9HC8ANzeaztsF x4x2SH4pkBEDlMQYg/W4x2FIhbU5010QNZHCzdNxRaukSS+SM5No1OSrEaiwxJ9ybsoB C83oY9OTi6EcuK4NzgWpvdgAhroOadYcEPPd7azSH11vtsjTuVijK+hDD3drt69FUKpq 0c3hZc1Hrbs7K3SPO5/NSwhxGarHaqvwaArIVEcCbdrLrdFwmNISymEcX7oco2jX0EwM mlgA== X-Gm-Message-State: AODbwcCNuQGOuojkg3S0hZQXLdmb5JEZyNAmPhiJQwJQyPXPm6bUWaeb yuWHKa+ghSRjNNC0MZcHm12GYyPKtGYUPGc= X-Received: by 10.36.41.7 with SMTP id p7mr3333544itp.113.1496167094594; Tue, 30 May 2017 10:58:14 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.107.12.159 with HTTP; Tue, 30 May 2017 10:58:14 -0700 (PDT) Date: Tue, 30 May 2017 11:58:14 -0600 X-Google-Sender-Auth: CJb91lkEiS6zczl0YS-ALgOzwGI Message-ID: To: internals Content-Type: text/plain; charset="UTF-8" Subject: [RFC]Discuss] Syntax for Arrow Functions From: levim@php.net (Levi Morrison) Internals, The previous discussion thread has died down significantly and so I'd like to start a new one to refocus. This message has some redundant information by design so people don't have to reference the other thread so much. Based on the discussion there are a few different syntax choices people liked. Overall it's a feature that people seem to want but everyone seems to prefer a different syntax choice. 1. fn(params) => expr 2. function(params) => expr 3. (params) ==> expr 4. (params) => expr Note that 3 and 4 require a more powerful grammar and parser and that 4 has ambiguities. I think we can work around them by rules -- only mentioning it because its popular because of JavaScript and do not prefer this at all. Note that 1 requires a new keyword. Option 2 looks the best from that perspective but is by far the longest; remember people are partially interested in this feature because they want shorter closures which this doesn't really help. This is why everyone is so divisive. All options have drawbacks. Additionally some people don't like binding by value and would prefer ref, and others really would be against by-ref. Which brings me to an option I don't think was ever discussed on list: 5. [](params) => expr // binds no values [=](params) => expr // binds by value [&](params) => expr // binds by reference It has quite a few good qualities: - No new keywords - Can choose between reference and value - Concise - Has precedence in C++, a major language - Can be done in our existing grammar and parser[1] - Can be extended to allow explicit binding of variables: // all equivalent // y is bound by value, array by reference [&, $y]($x) => $array[] = $x + $y [=, &$array]($x) => $array[] = $x + $y And of course it does have downsides: - Symbol soup (it uses a lot of symbols) - A minor BC break. Empty arrays which are invoked as functions are currently guaranteed to be errors at runtime and would have a new valid meaning. Here's an example from inside an array literal: // error at runtime previously [ []($x) => $x ] // now an array with one item which is a closure that returns its parameter Sara pointed out that we'd need to keep a leading `=` or `&` in the array to disambiguate from our array closure form. Overall I'd prefer 1 or 5. What do you guys think? [1]: I'm pretty sure it can be done but until it's done I can't say so confidently because sometimes there are things lurking in our grammar I forget about.