News for hackers. Stuff that matters.
Re:Pattern matching accepted for Python by pansa2 on Tuesday February 09, 2021 @06:31PM (#26083968)
In those other languages, if `not_found` is equal to 404 before the match block, how do you write a clause that only matches if `status` is 404?

Do you have to use the integer literal 404 instead of the named integer `not_found`?

Re:Pattern matching accepted for Python by heisenzombie on Wednesday February 10, 2021 @01:51AM (#26086297)
Elixir uses the “pin operator”

“Use the pin operator ^ when you want to pattern match against a variable’s existing value rather than rebinding the variable.”

    iex> not_found = 404
    404
    iex> ^not_found = 200
    ** (MatchError) no match of right hand side value: 200
https://elixir-lang.org/getting-started/pattern-matching.htm...
Re:Pattern matching accepted for Python by pfalcon on Wednesday February 10, 2021 @05:21AM (#26087471)
Exactly, Elixir is usually the only example given. So, how it makes sense to blame Python here is unclear. There's a proposal to add similar "sigils" to Python pattern matching, it just didn't make it yet.
Re:Pattern matching accepted for Python by yw3410 on Tuesday February 09, 2021 @06:51PM (#26084133)
Depends on the language, but a lot of them use guard clauses (so case ... if cond =>).
Re:Pattern matching accepted for Python by DougBTX on Tuesday February 09, 2021 @11:02PM (#26085612)
Re:Pattern matching accepted for Python by lou1306 on Wednesday February 10, 2021 @05:57AM (#26087670)
In OCaml and F# you can use `when`:

    match status with
    | n when n = not_found -> ...