Comment by user453
That's destructuring, a feature not a bug. Same as it works in any functional language - and tremendously useful once you get the hang of it
That's destructuring, a feature not a bug. Same as it works in any functional language - and tremendously useful once you get the hang of it
No, at least in Erlang a variable is assigned once, you can then match against that variable as it can't be reassigned:
NotFound = 404,
case Status of
NotFound -> "Not Found";
_ -> "Other Status"
end.
That snippet will return "Other Status" for Status = 400. The Python equivalent of that snippet is a SyntaxError as the first case is a catch all and the rest is unreachable.Destructuring yes but you can still argue it's poorly designed. Particularly unintuitive because matching on a nested name e.g. module.CONSTANT works for matching and doesn't destructure. It's just the use of an unnested name which does destructuring.
What Python needs is what Elixir has. A "pin" operator that forces the variable to be used as its value for matching, rather than destructuring.
At least functional languages tend to have block scope, so the latter snippet introduces a new variable that shadows `not_found` instead of mutating it.