Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104719 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68653 invoked from network); 14 Mar 2019 18:58:54 -0000 Received: from unknown (HELO mail-it1-f178.google.com) (209.85.166.178) by pb1.pair.com with SMTP; 14 Mar 2019 18:58:54 -0000 Received: by mail-it1-f178.google.com with SMTP id l139so5671809ita.5 for ; Thu, 14 Mar 2019 08:49:20 -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; bh=psy82+mp/g2RdYaOAvHyX8UL91zaxfF0uDrf5aFlPA8=; b=ii9SjDXJ5JpIZA8vnuX2LcZ5u80MO2WQO9C1BtdiQvYZ8IgYsFCwUYgLrLUciRR9i7 ubw+kmpxmDK3VCcFsIS8PKaTzI3hl0IVohwl1bK2dSnrv8NUfc4+08ptmKCHT2B+xqMJ +hXB06pQyZu0gfZ7vY9T1X+MN8IV9V3t4rQlKJl4qYE/tP6oyJZd/GTvxEB6wH5J3lyG i+j39n/WyUFwpNjb7dhJkOe2y5Mgnvr87GpmzEYrbjlOjIq62OiPSjCxeSPo31+3hRcz ir/yNmuxQVNpBqbfPlo8Oo2G31HqaimdxjdfZ03UEf2iJNaWS4RV9n5Hqf49OHdLtqdk CNyw== 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; bh=psy82+mp/g2RdYaOAvHyX8UL91zaxfF0uDrf5aFlPA8=; b=nE2sL4DFrXH/zlmBKiWYW4eAgRdA0av2RvOzvGZFHR8qOqtSATExTuu3GJArNedXw0 J/Qc4NqxN8YQx7bkhl4vgXqmzvY3bPJ8WVQaX7M7IthwbUIouiXHB3HKTOaeX5YQPAYl DR1MNL07SaS72ylOMCq1lXq/YxinuINhpmfpJPgEXZxMvJ672vVJvTMYq+LnMNJQ4qsj mL41+CXTJGc/rPfz1LbE2urc+IZe90hm3JzJ3f8c88npV2lP9qrqn7OArtr8z8EMd1n1 lJY4yoPv73wk63nCfAws1NUHdh9656fRO00RntRw6YeCc8a1Fjh8KeWEbS1pVgwhTqaa eJrg== X-Gm-Message-State: APjAAAXg59KBlGqOALJ8GiVIAnm6D/o6Rp4OnItEKwmuGiwuRtkG7nvt RpKY1oNg3XwwMzp6UHTA8moeqt6jIod+CbXK2WfbHBOg X-Google-Smtp-Source: APXvYqzspxpq1lsSvrMYrpkMce9absYM/m8PTP6gDvxoMmAuaEjvaH3WEHXvZFCAadRW3Ij/NZ/uV/vp6njvxH0VfW0= X-Received: by 2002:a24:d50:: with SMTP id 77mr2392830itx.139.1552578559165; Thu, 14 Mar 2019 08:49:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 14 Mar 2019 15:49:07 +0000 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000814fbb05840fdd46" Subject: Re: [PHP-DEV] [RFC] Arrow functions / short closures From: rowan.collins@gmail.com (Rowan Collins) --000000000000814fbb05840fdd46 Content-Type: text/plain; charset="UTF-8" On Thu, 14 Mar 2019 at 15:10, Benjamin Morel wrote: > 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 > I don't agree that this has anything to do with "purity". If JS didn't have => syntax, why would "fn is a shorter keyword than function" not be a good enough reason to go with this syntax? I think it's equally valid to say that it would be a shame for one syntax shortcut to take precedence over the consistency and maintainability of everything else in the language. Is it really that important to save two key strokes per closure? > 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. > A quick regex search in a code base I had to hand found a few instances of casts, like [(string)$foo => $bar], but indeed no instances of bracketed variables. However, it would feel rather bizarre to be able to write this: [ $x+1 => $foo ] But not this: [ ($x+1) => $foo ] Which I think would have to be the implication for this to make the parsing any easier. On Thu, 14 Mar 2019 at 15:38, David Rodrigues wrote: > maybe using [] instead of ()? For instance: "[$x] => $x + 1". PHP don't supports and array as key, so maybe it will not causes any conflict. Again, I think this solves the ambiguity but not the parsing, although I could be wrong. Consider parsing these three expressions: [ [ $foo ] ] # Nested arrays [ [ $foo => $bar ] ] # Nested arrays with an explicit key [ [ $foo ] => $bar ] # An array containing a closure Regards, -- Rowan Collins [IMSoP] --000000000000814fbb05840fdd46--