Skip to content

Instantly share code, notes, and snippets.

@cpurdy
Created July 26, 2022 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpurdy/4cc33bdc969044a96f911a473a2cdef3 to your computer and use it in GitHub Desktop.
Save cpurdy/4cc33bdc969044a96f911a473a2cdef3 to your computer and use it in GitHub Desktop.
module TestSimple
{
@Inject Console console;
void run()
{
function Int() f = makeMeAClosure();
console.println($"after losing the stack frame, the returned closure evaluates to {f()}");
}
function Int() makeMeAClosure()
{
Int x = 10;
Int y = 20;
function Int() closure = () -> x + y;
console.println($"before changing x and y, the closure evaluates to {closure()}");
x = 42;
y = 42;
console.println($"after changing x and y, the closure evaluates to {closure()}");
return closure;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment