Actions
Feature #16037
openAllow multiple single/double-splatted variables in `in` pattern matching and introduce non-greedy-splatted variables
Status:
Open
Assignee:
-
Target version:
-
Description
Pattern matching in in
argument seems to prohibit multiple occurrences of single/double-splatted variables.
case ["a", "b", 3, "c", "d"]; in *foo, Integer, bar; end # >> (Not SyntaxError)
case ["a", "b", 3, "c", "d"]; in *foo, Integer, *bar; end # >> SyntaxError: unexpected *
However, unlike conventional constant/variable assignment, it makes sense to have multiple occurrences of single/double-splatted variables in a single pattern matching provided that we have a definite rule regarding whether the splats are greedy or not.
I propose the following.
- Relax the syntax for pattern matching in
in
argument to allow multiple occurrences of single/double-splatted variables, and set up a rule regarding whether the splats are greedy or not; preferably greedy. - Further, introduce new syntax for non-greedy splats
*?foo
,**?foo
. Currently, they are syntactically invalid, so I don't think they would conflict with existing code.
case ["a", "b", 3, "c", "d", 6, "e", "f"]; in *foo, Integer, *bar; foo end # => ["a", "b", 3, "c", "d"]
case ["a", "b", 3, "c", "d", 6, "e", "f"]; in *?foo, Integer, *bar; foo end # => ["a", "b"]
Actions
Like0
Like0Like0Like0Like0Like0