3 ms·
The Lua interpreters, "upvalues" sound suspiciously like the results of Tcl's, "upvar", can anybody comment on how similar they actually are?
by mftb 4y ago
The Lua interpreters, "upvalues" sound suspiciously like the results of Tcl's, "upvar", can anybody comment on how similar they actually are?
- munificent 4y agoI 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)
- ufo 4y agoNowadays the upvalues in Lua are bona-fide lexical scoping a-la Scheme or Javascript. However, the name comes from Lua 4.0 where the upvalues worked in a more unusual way. Not in the same way as Tcl though, but just as surprising for the uninitiated. https://www.lua.org/manual/4.0/manual.html#4.6 https://www.lua.org/manual/4.0/manual.html#4.6
- mftb 4y agoInteresting ty, will review.