-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starlark: allow nested def statements
This change removes the restriction that def statements may not be nested. As in Python, Starlark's nested def statements are lexically scoped, and are implemented using closures, a technique first described in 1964 (for Landin's SECD machine) and employed in essentially every language since Scheme in the 1970s. The resolver computes the free variables of each function, which are in effect treated as hidden parameters implicitly supplied from the environment in which the def statement is executed. Local variables shared between outer and inner functions are indirect and called Cells. The tests now use the assert_fails(lambda: expr, "expected error") construct so that they can test failures without aborting the test chunk. (There is no lambda syntax yet, but its addition is trivial and will be done in a follow-up; see CL 345746527.) RELNOTES: Starlark now permits def statements to be nested (closures). PiperOrigin-RevId: 346365019
- Loading branch information
1 parent
fb1c369
commit 5ca2064
Showing
9 changed files
with
391 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.