3 ms·
> That's basically dynamic scoping instead of lexical scoping No, it's not a scoping change, the variable in the pattern is definitively in the scope (function
by dragonwriter 6y ago
> That's basically dynamic scoping instead of lexical scoping
No, it's not a scoping change, the variable in the pattern is definitively in the scope (function or module) containing the pattern match.
It's just non-determinism (or, no specification) as to what, if anything, gets assigned to it as a result of the failed pattern match.
- choeger 6y agoIt is. Normally, a match expression can bind variables to values. In lexical scoping, these variables exist inside the match expression. In dynamic scoping they exist outside. The design mistake seems to be to assume that the patterns inside a match expression should be regular expressions, whereas pattern expressions should be a dedicated syntactic category.
- dragonwriter 6y agoPython has lexical scoping in which modules, functions, and comprehensions are the only lexical units that introduce a new scope. The addition of pattern matching, and the UB around whether binding happens for failed matches, do not change that to dynamic scope, in which the course of execution, not the lexical structure, would determine visibility (e.g., variables would be visible in a function called from, even if not nested within, the one in which they were defined.)