The term "closure" is bandied about very casually but I feel like we should be more precise to avoid confusions in comments and documentation for clox.
Technically, a closure should refer only to functions that close over non-local, non-global variables (i.e., local variables in parent scopes). This happens when a function extends its lifetime beyond that of its defining scope by being returned. This means that any such captured local variables need to be migrated from the stack to a more permanent place (the heap or the stack of a top-level function guaranteed to exist until interpretation is done).
Functions that refer to non-local, non-global variables, but whose lifetime doesn't go beyond its parent's, are simply nested functions, but not closures.
The term "closure" is bandied about very casually but I feel like we should be more precise to avoid confusions in comments and documentation for
clox
.Technically, a closure should refer only to functions that close over non-local, non-global variables (i.e., local variables in parent scopes). This happens when a function extends its lifetime beyond that of its defining scope by being returned. This means that any such captured local variables need to be migrated from the stack to a more permanent place (the heap or the stack of a top-level function guaranteed to exist until interpretation is done).
Functions that refer to non-local, non-global variables, but whose lifetime doesn't go beyond its parent's, are simply nested functions, but not closures.