Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99287 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92683 invoked from network); 30 May 2017 22:26:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 May 2017 22:26:50 -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.223.176 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.223.176 mail-io0-f176.google.com Received: from [209.85.223.176] ([209.85.223.176:35862] helo=mail-io0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/28-43873-9A1FD295 for ; Tue, 30 May 2017 18:26:49 -0400 Received: by mail-io0-f176.google.com with SMTP id o12so1749816iod.3 for ; Tue, 30 May 2017 15:26:49 -0700 (PDT) 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:cc:content-transfer-encoding; bh=FurKTw+jWi34vBbxN7R7N7r+jkyKI0ygKqTG4OXr68o=; b=mr3UcU4iZupj1IFpJLJysiG4s6Im2s0W+PJ4PpoXUC8dr99i4fjX907J48auPOPrdp NZcKO3G7AflKQ0SXvtZIV1eiSMY33Nk/9Fy2I+n7nNiMtu+EjLWARsBUcURAtD3nNmZO 2//aXdIhbxkbOZTW4pUtRIZBh4cBDMoeDOvPv+oXFbnX0C83KFD9raQqejl1F+wV3eol 1+FLwY71jPcx3Nswgq9OMOiMqmzyZb3+SA4IKETV/1mCLVdzdCCR6xQOf9SBrzvyl2tG oHiw5/p1+QW0saHix0dol0rMfWEAVRI2ZS0RLXmGDSehufreesb3y4G3d/zEGsOMTCFr J8Ig== 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:cc:content-transfer-encoding; bh=FurKTw+jWi34vBbxN7R7N7r+jkyKI0ygKqTG4OXr68o=; b=h77Gcr0KjH7xVhCCkWQ/sf3FnIY10mUbBdBPyV71iHiRyIamsJtQbm+gsCV1UJov+Y 4fOYRsDsJdd/3AJDyzKSc+i14oTTOtzLtZ3AauuPZimSXJJ/oQBCGbpDILYozC6uWBh8 xA3dkEmOy5WfUdyjn1jf25AJAk+BaF0hD78SrE2NSumHcwgXa/TIAoMZ43EJTARKC5e+ YjLuyq1dvzh15g4sAArB/kH3cWk1twKkMQ8YpRSBjPBUhLGD2sNQ2niI0f7TeIImIaw9 SE2o4Nsh7svM+UC5yVZnsfMZaa7TARW/kw74Vg7uUnTzAk9z2xE4GLN6GGJAQwCUR7DF QRqA== X-Gm-Message-State: AODbwcCx2RyLJh2jDz6mwM5eKzOgfru1JxglGkscsBGTUxREDyGE4BZj eJpuL+Jv97l5JSfzzIpQXX2pI2UXbg== X-Received: by 10.107.151.79 with SMTP id z76mr20135763iod.98.1496183206344; Tue, 30 May 2017 15:26:46 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.107.12.159 with HTTP; Tue, 30 May 2017 15:26:45 -0700 (PDT) In-Reply-To: References: Date: Tue, 30 May 2017 16:26:45 -0600 X-Google-Sender-Auth: L5ku9Vwmcc_r3c7X9f0WAn3En14 Message-ID: To: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= Cc: Derick Rethans , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC]Discuss] Syntax for Arrow Functions From: levim@php.net (Levi Morrison) On Tue, May 30, 2017 at 3:37 PM, Bj=C3=B6rn Larsson wrote: > Den 2017-05-30 kl. 21:40, skrev Derick Rethans: > >> On Tue, 30 May 2017, Levi Morrison wrote: >> >>> 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) =3D> expr >>> 2. function(params) =3D> expr >>> >>> 3. (params) =3D=3D> expr >>> 4. (params) =3D> 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) =3D> expr // binds no values >>> [=3D](params) =3D> expr // binds by value >>> [&](params) =3D> 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) =3D> $array[] =3D $x + $y >>> [=3D, &$array]($x) =3D> $array[] =3D $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) =3D> $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 `=3D` or `&` in the >>> array to disambiguate from our array closure form. >>> >>> Overall I'd prefer 1 or 5. What do you guys think? >> >> I think 5 is terrible from a readability point of view. As you said it: >> "symbol soup". > > Do you think having =3D=3D> instead of =3D> would make it less of a > symbolic soup? If something is already symbol soup how does adding another symbol make it less so?