lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> > Right now, my only complain with the <toclose> is the term "close" that I
> > found a bit vague and over-loaded (conceptually).
>
> Suggestions are welcome.
>

In Java a class must implement AutoCloseable interface to ensure auto
closing in try/finally.
In C# I believe there is a similar interface IDisposable.
In Go, there is the defer statement that allows arbitrary code to be
run at scope exit.
In D I believe there are ScopeGuard statements 'scope(exit)' ,
'scope(success)' and 'scope(failure)' that basically get lowered to
try/finally and ensure code gets executed when scope is exited. D
allows the code to be executed conditionally (success/failure) or
unconditionally (exit).

If new keywords could be introduced, then one option might be:

with <var declarations> do
...
end

This could be syntactic sugar for:

do
   local <toclose> ....
end

Advantage of new keyword is that you avoid the ugly annotations.

I also like Daurnimator proposal of:

defer ... end

But I guess that doing this would mean changing the semantics to be
like Go, i.e. there will no longer be a __close metamethod, instead
one can run some code when scope terminates.


Regards
Dibyendu