[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [NoW] Deja vu
- From: Philippe Verdy <verdy_p@...>
- Date: Mon, 12 Aug 2019 12:38:25 +0200
No you can't! Every function is defined within a scope that always has many visible variables in scope (and not just in its environment). Not removing the visible variables that are not used by the function from the set of upvalues to include in its new closure would be a strong error. And when this set of used variables becomes empty, it makes no sense at all to instanciate dynamically a new closure (function reference): it should be static and created once by the compiler.
>> Moving functions out of a loop is not as simple as you think: the loop may not be visible at all and come from an invisible outer scope
If you are not depending on an upvalue you can always return a reference to function that is defined outside the scope that's returning it and thus return a the same version every time?