[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.4.0 (alpha) now available
- From: Dibyendu Majumdar <mobile@...>
- Date: Thu, 20 Jun 2019 22:06:40 +0100
On Thu, 20 Jun 2019 at 21:59, Patrick Donnelly <batrick@batbytes.com> wrote:
>
=> > 2) With regards to the 'toclose' variable declaration, introducing a
> > 'with' statement is the nicest approach.
> >
> > with <vars> = <initializers> do
> >
> > end
> >
> > This idiom is familiar to most programmers who use Python.
> > BTW @Patrick Donnelly this has nothing to do with Python's reasons for it etc.
>
> Quoting myself from the prior thread:
>
> "I want to point out the reasons why Python requires a control
> structure but Lua would not: Python's locals are function-scoped.
> Declaring a local in Python means it doesn't go out of scope until the
> function returns. For this reason, Python requires an explicit control
> structure to define the lifetime of the variable. Lua does not have
> this limitation."
>
> They absolutely needed another control structure to implement their
> flavor of RAII.
>
And I repeat that the suggestion to use this syntax doesn't have
anything to do with why Python had to have it. It is a nice idiom used
in many languages. C# calls it 'using'. In Java we have try with
resources. But all are the same construct.
Regards