3 ms·
> Therefore if you need to match against a calculated value, you can’t do the calculation inline. Instead you need to calculate the value outside the match and
by tom_mellior 6y ago
> Therefore if you need to match against a calculated value, you can’t do the calculation inline. Instead you need to calculate the value outside the match and give it a name - but you can’t match against a named local variable either!
Can you do either of those in other popular languages with pattern matching? Presumably the reason for wanting pattern matching wasn't to invent something completely new, but to implement something similar to pattern matching in other languages. (I know that C-style switches allow you to write constant arithmetic expressions in case labels.)
- pansa2 6y ago> Can you do either of those in other popular languages with pattern matching? Ruby supports matching against a local variable by pinning the variable (using a ^ prefix).