lua-users home
lua-l archive

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


On 08/17/2010 12:01 PM, Duncan Cross wrote:
On Tue, Aug 17, 2010 at 9:52 AM, Richard Hundt<richardhundt@gmail.com>  wrote:
Hi Lua Authors, List

Please don't shoot... but I have to ask because I really liked lexical
environments in work2. Is there any chance of reinstating the:

   in env do ... end

construct as sugar for:

   do local _ENV = ... end

?

The only justification I have for it is that it's not ugly (actually quite
the opposite). To me everything else about Lua 5.2 is beautiful, except
overloading un-prefixed symbol lookup/update by assigning to _ENV (the
semantics are perfect, I just find it ugly).

Anyway I thought it might be worth considering in light of the new and
improved Lua implementation (no more function environments, etc.).

If you all feel like hitting me with a stick now, then perhaps just remove
it from "The Complete Syntax of Lua" in the docs:

http://www.lua.org/work/doc/manual.html#9

Cheers,
Rich



I realise this is "their problem", but I think that in many people's
minds 'in env do' implies a lot more magic than the sugar is actually
providing, and explicit assigning to _ENV as a local variable is more
likely to force them to see how it actually works rather than how they
hoped it would work. It may be ugly, but it's less confusing.

In particular I remember when it was first mooted it seemed like quite
a few people assumed at least one of the following, and were surprised
if not frustrated when it turned out to be wrong:

I remember, the general expectation was that it behaved more like JavaScipt's with (obj) { ... }, but it registered with me as a setfenv() for do ... end blocks with all the same caveats, so I didn't find it surprising.


Now maybe this is just a documentation/education problem, but to me,
solving that problem and making damn sure that the laziest of users
really understands the subtleties of "in" seems like too much of a
headache for something that is, after all, now only sugar.


Anyway, I'm sold. Code that's easier to reason about is always a win.

Thanks for taking the time to humour me and give me a detailed response.

Cheers,
Richard