[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Another option for closing variables
- From: Sergey Kovalev <kovserg33@...>
- Date: Tue, 9 Jul 2019 01:23:04 +0300
пн, 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.