From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id C24CD1F4BD for ; Wed, 2 Oct 2019 03:25:01 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id CB546120A1C; Wed, 2 Oct 2019 12:24:51 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 85110120971 for ; Wed, 2 Oct 2019 12:24:49 +0900 (JST) Received: by filter0081p3las1.sendgrid.net with SMTP id filter0081p3las1-27180-5D941883-26 2019-10-02 03:24:51.466067961 +0000 UTC m=+31278.889991269 Received: from herokuapp.com (unknown [18.206.91.11]) by ismtpd0074p1iad2.sendgrid.net (SG) with ESMTP id _Yi5l93ST1GbTGKZ5Lhebg for ; Wed, 02 Oct 2019 03:24:51.365 +0000 (UTC) Date: Wed, 02 Oct 2019 03:24:51 +0000 (UTC) From: keystonelemur@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70735 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16182 X-Redmine-Issue-Author: mame X-Redmine-Issue-Assignee: matz X-Redmine-Sender: baweaver X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?XlD0LGPYDDjb=2FA1CQKGKXgvLTTlhHMIrQD1g5Sx7EbLedHWR4B0q9B6Nn8grUI?= =?us-ascii?Q?jY0y0+yd=2FRB17CMMomx7JzftZ7m+OlSPogzld6N?= =?us-ascii?Q?zTGAAtTeQq6qqKf+9imf0JebzfuQP=2FScvKzSy4L?= =?us-ascii?Q?rEZ8360QrGSoMtJAucr7SYT7JRqbAtF6VhKRFHh?= =?us-ascii?Q?2ZXAW2SaJzJxUcKNDuLDHP=2FOCJ3w9QJNETQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95180 Subject: [ruby-core:95180] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not? X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16182 has been updated by baweaver (Brandon Weaver). I wonder if it would make sense to reverse this to be left-to-right (LTR) rather than right-to-left (RTL) to make it easier to parse. I cannot think of another RTL syntax in Ruby at the moment, including the current `for ... in` statement: ``` for item in collection ``` A full example might be: ``` for a, b in { a: 1, b: 2 } p a, b end :a 1 :b 2 => {:a=>1, :b=>2} ``` Of course this does not currently work with keyword arguments: ``` [2] pry(main)> for a: 1, b: 2 in [{ a: 1 }, { b: 2 }] SyntaxError: unexpected ':', expecting '.' or &. or :: or '[' for a: 1, b: 2 in [{ a: 1 }, { b: 2... ^ [2] pry(main)> for a:, b: in [{ a: 1 }, { b: 2 }] SyntaxError: unexpected tSYMBEG, expecting do or '{' or '(' for a:, b: in [{ a: 1 }, { b: 2 }] ``` What if we leveraged some of the current logic for parsing a `for ... in` statement to make single-line pattern matching into a LTR syntax? This may be a solution for the parsing difficulties, as well as build on the intuition of Ruby developers expecting LTR syntaxes naturally. ---------------------------------------- Feature #16182: Should `expr in a, b, c` be allowed or not? https://bugs.ruby-lang.org/issues/16182#change-81813 * Author: mame (Yusuke Endoh) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) * Target version: ---------------------------------------- In #15865, a new syntax ` in ` was introduced. By using this, we can write: ``` json = { foo: 1, bar: 2} if json in { foo:, bar: } p [foo, bar] #=> [1, 2] end ``` However, we cannot write: ``` p(json in { foo:, bar: }) #=> expected: true, actual: syntax error ``` This is because ` in ` is an expression but not an argument. For example, `foo(json in a, b, c)` is ambiguous: it is considered `foo((json in a), b, c)` and `foo((json in a, b, c))`. What should we do? 1. Do nothing; we admit that it is a spec 2. Revert the feature 3. Disallow a pattern like `a, b, c` or `a:, b:, c:` in this one-line pattern matching syntax; we ask a user to write `json in [a, b, c]` or `json in {a:, b:, c:}` -- https://bugs.ruby-lang.org/