Project

General

Profile

Actions

Feature #17371

closed

Reintroduce `expr in pat`

Added by ktsj (Kazuki Tsujimoto) about 4 years ago. Updated about 4 years ago.

Status:
Closed
Assignee:
-
Target version:
[ruby-core:101262]

Description

How about reintroducing expr in pat, as akr-san proposed in DevelopersMeeting20201026Japan.

The difference between expr => pat and new expr in pat is the return value of the expression.

# expr => pat
0 => a #=> void (succeeded)
0 => 1 #=> NoMatchingPatternError (failed)

# expr in pat
0 in a #=> true (succeeded)
0 in 1 #=> false (failed)

Motivation and use cases are described at [Feature #15865].

I pointed out that there is a concern that in this specification a user might overlook the pattern did not match, and changed the return value at [Feature #16355].
However, now we already have new "rightward assignment style" pattern matching syntax, so we can say that this problem is solved.

If expr in pat is accepted, I also propose that the return value of expr => pat on a successful match be the left-hand side value.
Because, in this case, it becomes more clear that the use of expr => pat is assignment.


Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #15865: `<expr> in <pattern>` expressionClosedmatz (Yukihiro Matsumoto)Actions
Related to Ruby master - Feature #16355: Raise NoMatchingPatternError when `expr in pat` doesn't matchClosedActions
Actions #1

Updated by ktsj (Kazuki Tsujimoto) about 4 years ago

Actions #2

Updated by ktsj (Kazuki Tsujimoto) about 4 years ago

  • Related to Feature #16355: Raise NoMatchingPatternError when `expr in pat` doesn't match added
Actions #3

Updated by mame (Yusuke Endoh) about 4 years ago

  • Target version set to 3.0
Actions #4

Updated by ktsj (Kazuki Tsujimoto) about 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|88f3ce12d32ffbef983b0950743c20253ea2d0c6.


Reintroduce expr in pat [Feature #17371]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0