What is the point of closed functions?

Hi,

I’ve come across the notion of a “closed” function.

As far as I understand it it is a “pure” function that only depends on it’s arguments and does not refer to any “outer” variables from an environment.

While I can see that from an implementation point of view there is probably some optimization to be gained when you don’t need to keep track of an environment, however I cannot see why you need the special syntax “#{…}” for that…

Should the compiler/interpreter not be clever enough to figure out that a function does not refer to any environment and provide some optimization without having to tell him explicitly?

As far as I understand it marking a funktion as “closed” does not do anything, apart from (probably) some optimization on the implementation level and that could be figured out without the user/programmer having to explicitly mark a function as “closed”…

What am I missing/not understanding?

Many thanks!

In fact, the compiler does automatically recognize a closed function definition.

The usefulness of the #{ } notation is: if you want to be sure a function is closed (and that future modifications don’t accidentally open its scope), add the # before it. Then any future alterations that refer to external variables will cause a compiler error, and you know that a mistake has been made.

hjh