lua-users home
lua-l archive

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


On Fri, Jun 21, 2019 at 2:48 PM Dibyendu Majumdar
<mobile@majumdar.org.uk> wrote:
>
> On Fri, 21 Jun 2019 at 21:35, Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
> >
> > >>>>> "Dibyendu" == Dibyendu Majumdar <mobile@majumdar.org.uk> writes:
> >
> >  Dibyendu> 1) Adding a 'toclose' variable in the 'for' loop is an
> >  Dibyendu> undesirable feature in my opinion. Not aware of any language
> >  Dibyendu> that does that.
> >
> > You do realize that this is one of the primary reasons for 'toclose' to
> > exist at all? The fact that breaking or erroring out of a loop doesn't
> > give the iterator any chance to clean up is a significant problem (for
> > example, if iterating over io.lines, the file is not closed until it is
> > GC'd, which may not happen until much later).
> >
>
> Not sure I understand ... no language I know has this, and yet many
> have autoclosing of resources, so clearly it is not the reason for
> toclose.

For io.lines, Lua automatically closes the file after the last
(successful) line. Unfortunately, there's no integration with the
generic for loop in Lua 5.4. It would be nice if the internal state
variable could be closed when the loop breaks. I guess the Lua authors
have good reasons for not making that change beyond the trivial reason
that the state value in existing code may not be closeable.

-- 
Patrick Donnelly