r/ProgrammingLanguages • • May 09 '26

Blog post The Namespace Problem

https://www.alialmutawajr.com/blog/post1
14 Upvotes

14 comments sorted by

View all comments

Show parent comment

-4

u/Pie-Lang May 10 '26

Take this case for example:

x = 1;
closure = () => print(x);
x = 2;
closure();

If the closure captured x at the definition-site instead of call-site, then 1 would be printed. That's not the behaviour that I want.

As for your example of returning a closure. Pie currently captures the surrounding environment only if it's returned from/passed to a function.

foo = () => {
    x = 42;
    () => x;
};

This does work as expected in Pie!

26

u/A1oso May 10 '26

Then the closure should capture a reference to x.

3

u/Pie-Lang May 10 '26

Good point.