r/ProgrammingLanguages • u/Pie-Lang • May 09 '26
Blog post The Namespace Problem
https://www.alialmutawajr.com/blog/post1
14
Upvotes
r/ProgrammingLanguages • u/Pie-Lang • May 09 '26
31
u/A1oso May 10 '26 edited May 10 '26
In most languages, variables used in a lambda/closure are resolved when the closure is created, not when it is invoked:
This doesn't require any static analysis. The closure "captures" the value of x when the closure is created, not when invoked. This completely sidesteps your problem. It also enables this pattern:
The closure can access x even after returned from the function, when x is no longer in scope, because x has been captured.
7
u/TOMZ_EXTRA May 10 '26
I may have misunderstood what you mean, but doesn't Lua already represent namespaces as tables (hashmaps) without any issues?
24
u/AustinVelonaut Admiran May 10 '26
You've re-discovered the problems that early LISP implementations had with dynamic scoping -- it is hard to reason about things just by looking at the static source code. Especially when you have nested scopes and closures. Dynamic scoping still has some uses, but isn't great for a general strategy.