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.
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)
Pretty much the same as in the PEP: https://www.python.org/dev/peps/pep-0636/#adding-conditions-...
Do you have to use the integer literal 404 instead of the named integer `not_found`?