lua-users home
lua-l archive

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


On Wed, Jul 18, 2018 at 11:55 PM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
It is not by chance that Lua avoids too many syntactical constructs.
They are hard to be represented in the C API.

If "with" is syntax sugar on top of scoped vars then a representation in the C API isn't needed.

The benefits of "with" syntax are related to readability:  1) it's clear by code structure that a resource is open, and 2) named variables can be elided in many cases, e.g.:

    with my_lock:scoped() do ... end

Proposed pseudocode for "with":

A with statement like

     with exp_1, ···, exp_n do block end

is equivalent to the code:

     do
         local scoped var_1, ···, var_n = exp_1, ···, exp_n
         block
     end

where var_i are invisible.

with ... as statement like

     with exp_1, ···, exp_n as var_1, ..., var_n do block end

is equivalent to the code:

     do
         local scoped var_1, ···, var_n = exp_1, ···, exp_n
         block
     end