lua-users home
lua-l archive

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


On Tue, Feb 17, 2009 at 12:01 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> > What's wrong with Joonas Pihlaja's proposal?
>> >
>> >  do with f, g = io.open("src.txt","r"), io.open("dst.txt",w")
>> >     for l in f:lines() do
>> >        ...
>> >        g:write(l)
>> >     end
>> >  end
>> >
>> > (Probably with a different syntax...)
>> >
>>
>>
>> I've been using it in metalua for a while (syntax "with <var_list> =
>> <values_list> do <scoped_statements> end") for some time, with the
>> convention that the protected variables must have a ":close()" disposal
>> method, and I'm pretty happy with it.
>
> I do not see why the need for the <scoped_statements>. It would be
> simpler to add only a new form of locals. Something like
>
>  local finalized f, g = ...
>
> that calls ":close()" (or __gc??) when it goes out of scope.  Of course,
> you can (should?) use a conventional do-end around it:
>
>  do local finalized f, g = ...
>    ...
>  end
>
> But the do-end is not part of the syntax.

I've already enumerated all these options in the original post and
described some trade-offs (point #5).  I'm not so concerned about what
syntax is used, just that a solution gets into the language.

...or my answer could be that I already proposed that two years ago
and got ignored :)

   http://lua-users.org/lists/lua-l/2007-05/msg00354.html