Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104715 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54548 invoked from network); 14 Mar 2019 18:19:46 -0000 Received: from unknown (HELO mail-yw1-f66.google.com) (209.85.161.66) by pb1.pair.com with SMTP; 14 Mar 2019 18:19:46 -0000 Received: by mail-yw1-f66.google.com with SMTP id c4so4661481ywa.11 for ; Thu, 14 Mar 2019 08:10:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4kaKRD33ESy2pRmrX6ugrE+6GKL4TqPT0Wsj/GajnoY=; b=ZESUmjx6k06v+JxxykqT9ii1tmEOcFfth77s2Q16WGhDLO9A7rgFaFp7UkkZwrXes9 07P7SxbX/CHot4kGqnYHS4tFoIJt/529DQLlnD3Bcss6RukGAlKh3Ejodjni1fU+GLYX V71s/tvj78k3qd25Xp+l1GKvYf+1ehl/TtCegLDRaBHaEPL4KVoBkVEbeoUK7CXFJ7nA lyGHoJQOpwhd/fif6gzRlXZXruRpjq9+l/Vh6RtB1X1oNZVfhaIRxK2rmraSqAxqwn7r HOaSuaAn4P6782/m02mtX0Ed0fv2xNGAIxhAr+3fzyfk7HYiqCHXYdD4Lw7lgg09zjLP e5pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4kaKRD33ESy2pRmrX6ugrE+6GKL4TqPT0Wsj/GajnoY=; b=a5JCWwR5rbjP0T3dRNviy+DxT/vY2jXVZdzsIRegorzAphsEt4uc2G9mlfmO90vtMa tN+uaBViWSRpsUItNazpKsNDEO42ExGvlzd4jQNs2m/Muw7nqX5u117aNxcO+kq23DCL c5QoifBPKTkjKVpzKE/+j/v9VxuWM7oc+WEVyA+IMaStYsQB4VRHUXe0Iq5ON7csfOKb YzQ4vtp8cTfHvlvZ7jiIGdVgs7T/BP8/RrXPG7c68BB55bxU4hW+p9OtZl+ncnUJAg+4 YB33agmmdiyHFLpM+hwcuckGtr/tm14Mv2hkLbAwwuFHLh0zA4f6OM3N1F0qa1OfiAge HLJQ== X-Gm-Message-State: APjAAAU1g5wqBLQ8RuIXtMH4AkxkxSYnoW0wNXvchumaLUCBWBdUwula eMeToPhCOaey/EjgSBFEumWNjI7KZZRCenSCeBY= X-Google-Smtp-Source: APXvYqztENj5qrCWfLd5hPSMG12nHBiQIp1SIsSTwhvW3gNNH/AJraAml/wRyemoDMQMgNtk7rernyFA+zR05i3zcs0= X-Received: by 2002:a81:178c:: with SMTP id 134mr18665412ywx.480.1552576210690; Thu, 14 Mar 2019 08:10:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 14 Mar 2019 16:09:58 +0100 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008665ff05840f516b" Subject: Re: [PHP-DEV] [RFC] Arrow functions / short closures From: benjamin.morel@gmail.com (Benjamin Morel) --0000000000008665ff05840f516b Content-Type: text/plain; charset="UTF-8" > > The problem, as I understand it, is not avoiding ambiguity, it's avoiding > lookahead. You're right, I was only thinking about resolving the ambiguity with array keys. It's too bad if the parser implementation considerations take precedence over the purity of the language, but I can understand the maintenance nightmare that people are trying to avoid here. Something else that crosses my mind, is: what prevents us from using the same syntax as ES6: ($x) => $x * $y But to prevent any ambiguity, forbid array keys from being enclosed with parenthese? For example, the following would be considered an array containing a closure: [ ($foo) => "bar" ] And the following would just become a syntax error: [ ("foo") => "bar" ] Would that solve the parser problem? BC-wise, I don't think this would be much of a problem: I have yet to see array keys enclosed with parentheses in PHP codebases. On Thu, 14 Mar 2019 at 15:54, Rowan Collins wrote: > On Thu, 14 Mar 2019 at 14:12, Benjamin Morel > wrote: > > > This makes me thinking, has this syntax been considered? > > > > ($x) => { $x * $y } > > > > Nested: > > > > ($x) => { ($y) => { $x * $y } } > > > > > Wouldn't this have all the same parser problems as the RFC discusses? > > The problem, as I understand it, is not avoiding ambiguity, it's avoiding > lookahead. If you write: > > $foo = [ ($x) => { $x } ]; > $bar = [ ($x) => $x ]; > > The parser has already consumed " [ ($x) =>" before it can decide if each > ($x) is an array key or a closure signature. It's parseable, but only using > one of the workarounds described in the RFC. > > If I'm understanding the RFC correctly, the only way to avoid that is to > have closures *start* differently from other valid constructs, because then > the parser doesn't need to recurse / backtrack / etc. > > Regards, > -- > Rowan Collins > [IMSoP] > --0000000000008665ff05840f516b--