Hacker News new | past | comments | ask | show | jobs | submit login

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




I'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.


A 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)


Cool, Crafting Interpreters is on my list anyway, so I'll check it out, ty.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: