lua-users home
lua-l archive

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


On Fri, Mar 31, 2017 at 12:24 PM, William Ahern <william@25thandclement.com> wrote:

Either Roberto or Luiz once proposed a construct that automatically invoked
a __close metamethod on an object upon exiting a block. IIRC, it would be
invoked even if scope exit occured because an error was thrown.

I thought that was a cool idea. It's similar to the using, with, and defer
statements of other languages.

It sometimes looks like this list is trying to reinvent Scheme one feature at a time. None of the above languages
have coroutines (or it's Scheme cousin: call-with-current-continuation), and 'exit means exit'.

Not so with coroutines, yield exits a block, but it may or may not return. If you're holding a lock using an RAII-style
userdata you may be in trouble, either because after a resume you run your code without owning the lock, or the coroutine
never gets resumed, and the lock is held way too long. 

Coming up with sensible semantics may be harder than actually implementing this feature.

(The 'solution' in Scheme is to have the programmer figure it out, and provide a feature called 'dynamic-wind', not pretty)


--
--