"Structural pattern matching" for Python, part 2
"Structural pattern matching" for Python, part 2
Posted Sep 3, 2020 22:48 UTC (Thu) by NYKevin (subscriber, #129325)In reply to: "Structural pattern matching" for Python, part 2 by sbaugh
Parent article: "Structural pattern matching" for Python, part 2
lambda does create a new lexical scope already, and it doesn't help with that problem. In order for your example to work "correctly," you would need to establish a new lexical scope for each iteration (not just one for the whole loop, because it would still have i=4 at the end of the loop). I would find that very hard to reason about, because that's not what I think of when I hear the word "lexical."
What (I think) you really want is capture-by-value semantics instead of capture-by-name, which has nothing to do with whether or not the loop has a separate scope.
