lua-users home
lua-l archive

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




On 2019-06-21 5:34 p.m., Andrew Gierth 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).


I'm convinced <toclose> should support nested contexts (read: have an __enter).

I have, many times, used file:lines() (which is more like file:read_iter() because you can give it args) in a loop that I would break out of, and then I'd use the file some more.