[#97536] [Ruby master Bug#16694] JIT vs hardened GCC with PCH — v.ondruch@...
Issue #16694 has been reported by vo.x (Vit Ondruch).
11 messages
2020/03/18
[ruby-core:97347] [Ruby master Feature#16670] Reverse order of `expression` in `pattern` for 1-line pattern matching while it's still experimental
From:
zverok.offline@...
Date:
2020-03-03 16:15:41 UTC
List:
ruby-core #97347
Issue #16670 has been updated by zverok (Victor Shepelev).
In favor of the proposal, standalone match looks this way in other languages:
```
# Rust:
let (x, y, z) = (1, 2, 3);
# Erlang:
{X, Y} = {1, 2}.
# Elixir:
{a, b, c} = {:hello, "world", 42}
# F#:
let {First=first} = alice
# Swift (?):
case let Media.movie(title, _, _) = m
```
(Probably there could be more examples, though I am not super-familiar with many languages, and for what I can judge from online docs, lot of them -- like Haskell or OCaml -- seem not to have standalone `let` expression, just `match` with several alternative patterns)
----------------------------------------
Feature #16670: Reverse order of `expression` in `pattern` for 1-line pattern matching while it's still experimental
https://bugs.ruby-lang.org/issues/16670#change-84467
* Author: ttilberg (Tim Tilberg)
* Status: Open
* Priority: Normal
----------------------------------------
Currently the 1-line syntax for pattern matching is:
```
# Usage: <expression> in <pattern>
expression = {
pattern: "Example"
}
expression in {pattern: something}
# something => "Example"
```
Is it technically possible, and desirable to switch the order of this syntax to:
```
# Usage: <pattern> in <expression>
expression = {
pattern: "Example"
}
{pattern: something} in expression
# something => "Example"
```
?
Here are my reasons:
- It is more intuitive in English -- we are "finding a pattern in something". Finding "something in a pattern" doesn't seem to make sense.
- Assignment is happening, and this keeps assignment on the left side of the operator which feels more natural.
- It matches existing behavior with the workings of the case statement:
Understanding that a `case` block evaluates each `when` expression using `when_expression === case_expression` makes more consistency with `when_pattern in case_pattern` using the new operator.
```
case something
when /pattern/
end
# is equivalent to
/pattern/ === something
# This creates more parity with
case something
in {pattern: x}
# would be equivalent to
{pattern: x} in something
```
Please see the following discussion on Reddit: https://www.reddit.com/r/ruby/comments/favshb/27s_pattern_matching_official_docs_recently_merged/fj2c7ng/
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>