From: keystonelemur@... Date: 2019-10-02T03:24:51+00:00 Subject: [ruby-core:95180] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not? 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/ Unsubscribe: