Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify distinction between "function" and "closure" in clox #32

Open
zxul767 opened this issue Dec 9, 2022 · 0 comments
Open

clarify distinction between "function" and "closure" in clox #32

zxul767 opened this issue Dec 9, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation p1 refactoring

Comments

@zxul767
Copy link
Owner

zxul767 commented Dec 9, 2022

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.

@zxul767 zxul767 added documentation Improvements or additions to documentation refactoring p1 labels Dec 9, 2022
@zxul767 zxul767 mentioned this issue Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation p1 refactoring
Projects
None yet
Development

No branches or pull requests

1 participant