ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: matz@ruby.or.jp
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95185] [Ruby master Feature#16182] Should `expr in a, b, c` be allowed or not?
Date: Wed, 02 Oct 2019 08:05:30 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-81817.20191002080530.e9a0dba4004d095b@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16182.20190926080401@ruby-lang.org

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/

      parent reply	other threads:[~2019-10-02  8:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 ` matz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-81817.20191002080530.e9a0dba4004d095b@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).