* [ruby-core:95098] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not?
[not found] <redmine.issue-16182.20190926080401@ruby-lang.org>
@ 2019-09-26 8:04 ` mame
2019-10-01 13:36 ` [ruby-core:95171] " shevegen
` (2 subsequent siblings)
3 siblings, 0 replies; 4+ messages in thread
From: mame @ 2019-09-26 8:04 UTC (permalink / raw)
To: ruby-core
Issue #16182 has been reported by mame (Yusuke Endoh).
----------------------------------------
Feature #16182: Should `expr in a, b, c` be allowed or not?
https://bugs.ruby-lang.org/issues/16182
* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
In #15865, a new syntax `<expr> in <pattern>` 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 `<expr> in <pattern>` 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/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:95171] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not?
[not found] <redmine.issue-16182.20190926080401@ruby-lang.org>
2019-09-26 8:04 ` [ruby-core:95098] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not? mame
@ 2019-10-01 13:36 ` shevegen
2019-10-02 3:24 ` [ruby-core:95180] " keystonelemur
2019-10-02 8:05 ` [ruby-core:95185] " matz
3 siblings, 0 replies; 4+ messages in thread
From: shevegen @ 2019-10-01 13:36 UTC (permalink / raw)
To: ruby-core
Issue #16182 has been updated by shevegen (Robert A. Heiler).
I can not comment/answer on the issue and questions; I think this is for
matz and the core team to decide either way, whatever the way.
I did, however had, want to add that:
json in {a:, b:, c:}
is quite difficult to read (for me). So even if this may not be an ideal explanation,
but ... I would not be at all opposed to disallowing that, merely syntax-wise
alone. ;-)
(I do not really have a big opinion on the functionality in general but ideally
my personal taste is to prefer simpler syntax, whenever that is possible. We have
in general quite some suggestions that combine a lot of complex syntax together,
which I think is not ideal, in general; also in other proposals.)
----------------------------------------
Feature #16182: Should `expr in a, b, c` be allowed or not?
https://bugs.ruby-lang.org/issues/16182#change-81807
* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
In #15865, a new syntax `<expr> in <pattern>` 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 `<expr> in <pattern>` 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/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:95180] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not?
[not found] <redmine.issue-16182.20190926080401@ruby-lang.org>
2019-09-26 8:04 ` [ruby-core:95098] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not? mame
2019-10-01 13:36 ` [ruby-core:95171] " shevegen
@ 2019-10-02 3:24 ` keystonelemur
2019-10-02 8:05 ` [ruby-core:95185] " matz
3 siblings, 0 replies; 4+ messages in thread
From: keystonelemur @ 2019-10-02 3:24 UTC (permalink / raw)
To: 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 `<expr> in <pattern>` 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 `<expr> in <pattern>` 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/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:95185] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not?
[not found] <redmine.issue-16182.20190926080401@ruby-lang.org>
` (2 preceding siblings ...)
2019-10-02 3:24 ` [ruby-core:95180] " keystonelemur
@ 2019-10-02 8:05 ` matz
3 siblings, 0 replies; 4+ messages in thread
From: matz @ 2019-10-02 8:05 UTC (permalink / raw)
To: ruby-core
Issue #16182 has been updated by matz (Yukihiro Matsumoto).
I vote for 3 in the OP.
Matz.
----------------------------------------
Feature #16182: Should `expr in a, b, c` be allowed or not?
https://bugs.ruby-lang.org/issues/16182#change-81817
* Author: mame (Yusuke Endoh)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
----------------------------------------
In #15865, a new syntax `<expr> in <pattern>` 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 `<expr> in <pattern>` 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/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-10-02 8:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <redmine.issue-16182.20190926080401@ruby-lang.org>
2019-09-26 8:04 ` [ruby-core:95098] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not? mame
2019-10-01 13:36 ` [ruby-core:95171] " shevegen
2019-10-02 3:24 ` [ruby-core:95180] " keystonelemur
2019-10-02 8:05 ` [ruby-core:95185] " matz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).