tialaramex 3 days ago

Which x? There are two in your code, one for each time you introduce a pattern Some(x) and each x has scope which of course ends when that pattern is done with

Notice that the Python doesn't work this way, we didn't make a new variable but instead changed the existing one.

Also, the intent in the Python was a constant, in Rust we'd give this constant an uppercase name by convention, but regardless it's a constant and so of course matching against a constant does what you expect, it can't re-bind a constant, 404 is a constant and so is `const NOT_FOUND: u16 = 404;`

  • almostgotcaught 3 days ago

    > Which x? There are two in your code, one for each time you introduce a pattern Some(x) and each x has scope which of course ends when that pattern is done with

    if each x's scope ends at the end of each case doesn't that mean there's only one x?

    > we didn't make a new variable but instead changed the existing one.

    so because python doesn't have scopes except for function scopes it shouldn't ever have any new features that intersect with scope?

    • Spivak 3 days ago

      Also this is pretty much in line for the rest of Python leaving variables around.

          for x in [1]:
            pass
          print(x) # => 1
      
      The match statement presented is equivalent to an assignment, you do have to know that, but then it's just regular Python.
      • instig007 3 days ago

        Being in line with the bad original design decision is another bad design decision, python developers should have a courage to admit these instances to benefit from better decisions in new peps. They didn't do it with pattern matching and now the language has another inferior implementation of a feature that, if implemented correctly, should have had clear block scopes, defined as expressions (as opposed to statements), and disallowed type-diverging branches. Java has designed it right, by the way, despite having a differently behaving switch statement in the language already.

pansa2 3 days ago

> you simply don't understand what a match statement is

It's "a DSL contrived to look like Python, and to be used inside of Python, but with very different semantics":

https://discuss.python.org/t/gauging-sentiment-on-pattern-ma...

  • almostgotcaught 3 days ago

    you linked to a random detractors rant. i don't see what that has to do with whether a match statement binds a match?