Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98137 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66249 invoked from network); 3 Feb 2017 17:53:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Feb 2017 17:53:24 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.47 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.215.47 mail-lf0-f47.google.com Received: from [209.85.215.47] ([209.85.215.47:35105] helo=mail-lf0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3F/63-38491-393C4985 for ; Fri, 03 Feb 2017 12:53:23 -0500 Received: by mail-lf0-f47.google.com with SMTP id n124so14067125lfd.2 for ; Fri, 03 Feb 2017 09:53:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to; bh=tXVJ8rgZ5oh4QHfs2MHmDt6ubKe8zenbJF1fucfSO2I=; b=fRBEPbIyNcmE1At2oWzNf0dD5i7Hlpp89c1hRCqqWx35pJLd6KbvHIb62eRgLMDP6w qk+M/cxLMAsbVF2qbfMebcqSHTzmx+jy6/vyVuGJksjzl4e1Bd/xB50jjKkrl+hMjT97 Dk6x/4yhsW2rJYKed7oyzP0y0eUFGOYCE5X6Ksr6S1D4cQ6rZD0lnfzPUKYeAXfrcXe/ X/hlADHwekDSWAVenkSjcHkjSiesmipKqWqdl7kwOXkgvaaEJCA12dEaP7tq3Lwgbhw1 Mf078Yw6VvomCSykqN+F53KRmxjX0xosc3+CnCBpWF+Qep90h30exALyzrufBMhohAiU 2cNw== 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:in-reply-to:references:from :date:message-id:subject:to; bh=tXVJ8rgZ5oh4QHfs2MHmDt6ubKe8zenbJF1fucfSO2I=; b=KoRtg6HMcxIMdWligRvoTFZEqpkcv7lVE0oQyJC2lfiwgFkV5YLPZHP3tIRxd+N0b3 jPIkhNvy/8YI34QeaFtMasVpgHaIVkWV/SWnpA++lK/TGQnbE56JQRBF+TOlHoKb70B8 BAalTHJ2q2i3kfjwa7uhY/mces74CQGD7qhc+GFza2e2uVXtJnUXpj67zG0Lk8i7HGCp TAIvlDD/EM+5hOfe4eX2qQZ5ghBncE/37tUzN/HxvIAydO3goXMzOH7WfjsJEK2hvV8s jsnq/Df6Ad0jnAOGjg7Kz/Jvxur2wC6jGFe548aV9y5jKRdEt9t1973dqf/0z2ClS97x EapA== X-Gm-Message-State: AIkVDXLgTt1/TDaRmS+qIUuhOC/2G6IUtubfpDm84n2kTvGO70F/k8mvJnkIVUYFp01bI+GLA+D1dR6c/EsMXQ== X-Received: by 10.25.17.198 with SMTP id 67mr5323264lfr.39.1486144399472; Fri, 03 Feb 2017 09:53:19 -0800 (PST) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.25.151.139 with HTTP; Fri, 3 Feb 2017 09:53:18 -0800 (PST) In-Reply-To: References: Date: Fri, 3 Feb 2017 10:53:18 -0700 X-Google-Sender-Auth: aAPoYpA7KN16AvPt6hfiIp5HGwA Message-ID: To: internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [RFC][Discuss] Arrow Functions From: levim@php.net (Levi Morrison) On Fri, Feb 3, 2017 at 10:48 AM, Levi Morrison wrote: > On Mon, Jan 30, 2017 at 10:55 AM, 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 > > Thanks to everyone who has participated in the discussion thus far. > Primarily the feedback has been directed at the `fn` keyword. Let me > provide two benefits and drawbacks of using `fn` as a keyword: > > 1. `fn` is searchable in search engines and in our manual > 2. Is more intuitive than just syntax > > However, `fn` does have downsides: > > 1. Can break existing code > 2. We already have a similar keyword `function` > > To that end, I'd like to gauge interest in a pure syntax based > alternative that is similar to Rust and Ruby. > Instead of: > > fn(params) => expr > > What about: > > |params| => expr > > This trades the advantages of the keyword for the advantages of pure > syntax, and happens to be two characters shorter. To be explicit: > > 1. Preserves 100% backwards compatibility > 2. Avoids having two keywords that both mean "function" > 3. Is not easily searchable in engines or in the manual > 4. Is a tad bit shorter > > What do you think, Internals? One more thing: I'd like to re-emphasize that the syntax that JavaScript uses and the one that HHVM/Hack uses are ambiguous in the current class of our grammar. The following will not work unless we move to a more powerful grammar and parser class: (params) => expr (params) ==> expr This is why an un-ambiguous prefix is necessary: the prefix breaks the ambiguities. The syntax I have suggested in the RFC and the one I suggested just now are not ambiguous because distinct prefixes: fn(params) => expr |params| => expr I look forward to more discussion!