3 ms·
I don't think there's any deep connection. "upvar" in Tcl is a language feature. Upvalues in Lua are purely an implementation detail of the interpreter. If you
by munificent 4y ago
I don't think there's any deep connection. "upvar" in Tcl is a language feature. Upvalues in Lua are purely an implementation detail of the interpreter.
If you want all the gritty details, a chapter of Crafting Interpreters walks through a complete implementation of Lua's approach to closures:
http://craftinginterpreters.com/closures.html http://craftinginterpreters.com/closures.html
- mftb 4y agoCool, Crafting Interpreters is on my list anyway, so I'll check it out, ty.
- giraffe_lady 4y agoI'm not sure about that though I haven't used tcl in a while and was never an expert. I think tcl upvar allows you to explicitly do what lua's closure implementation automatically does. They aren't the same thing but they are closely related concepts and similar solutions to the same potential problem.
- ufo 4y agoA big difference is that Tcl's upvar is dynamically scoped. A more appropriate Lua analog would be Lua's debug API (e.g. debug.setlocal)