lua-users home
lua-l archive

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




On Mon, Jul 8, 2019 at 5:23 PM Sergey Kovalev <kovserg33@gmail.com> wrote:
пн, 8 июл. 2019 г. в 20:33, Gé Weijers <ge@weijers.org>:
>
> Yes, you can do without "local <toclose>", but I would not call your example readable code. The point of adding features like this to a language is to make programs simpler and easier to understand by increasing the expressive power of the language.
>
> This is a whole lot more readable:
>
> local <toclose> f = assert(io.open("test.txt", "r"))
> -- do something with f
> return value

I think this is readable enough:
local f=auto(io.close){ io.open("test.txt","r") }
-- do something with f
return value

And do it same things.
Boiler plate code "scope.begin" and "scope.end" be hidden for example
by transpiler or preprocessor.


Well YEAH, of course you can do it if you add a preprocessing phase. That's cheating. :P It's not really Lua anymore if you do that.

/s/ Adam