On 24 Nov 2015, at 4:52 pm, Roberto Ierusalimschy <email@example.com> wrote:
> What is wrong with the following proposal?
> local <some mark to be invented> name = exp
> Unlike a regular 'local' declaration, this one must define only one
> variable and it must be initialized. (Both restrictions could be easily
> removed; they are more about programming style.)
> When the local 'name' goes out of scope, then:
> 1 - if its value is a function, that function is called (no parameters)
> 2 - if its value is a table/userdata, its __close (or some other new
> name) metamethod, if present, is called.
I do like the sound of that. It nicely sidesteps the whole GC-vs-refcounting scoping debate, because it won't be finalising or deallocing the value concerned, only calling its __close metamethod, which really is all I've ever wanted from such a construct.