lua-users home
lua-l archive

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


On Thu, 20 Jun 2019 at 21:51, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> 2) With regards to the 'toclose' variable declaration, introducing a
> 'with' statement is the nicest approach.
>
> with <vars> = <initializers> do
>
> end
>

I realize now that because of the multiple return values from
io.open(), above is not possible, because a 'with' statement would
require that all vars declared are to-be-closed.
When I first saw the introduction of the *toclose annotation, I had
not understood why the annotation was necessary - as I hadn't
understood the ambiguity in syntax without some form of annotation
marker. So it seems we are stuck with some form of annotated local
declaration.

It is interesting how past syntactical choices limit options for
future evolution of the language.

In some ways an ugly syntax for 'toclose' declarations is not a bad
thing, as they draw attention of the reader to the fact. Also explicit
declarations are important for the same reason, and that is why I
think performing automatic close() in a generic for loop is not a good
idea as the reader of the code can't tell what is potentially
happening behind the scenes.

However the ugly syntax for a constant declaration is the side effect
of this; and that is a heavy price to pay. Given that the constant
feature seems to have been added because it was 'free' - perhaps, it
shouldn't be added to the language.

Anyway I am eager to see what comes out of all this. As a feature the
*toclose feature is an important one I think, more important than any
other feature in 5.4 I think. I can't wait to port this to Ravi once
it is finalised.

Regards
Dibyendu