lua-users home
lua-l archive

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


[ This is a small observation which doesn't really say anything new, but
this way of saying it gave me a better understanding of the arguments we
have been having. ]

Scheme has the terminology "binding form" to describe any syntax that
introduces new variables into scope, for example, lambda, let, etc.
Macrologists can define new binding forms without violating lexical
discipline.

In Lua there are three explicit binding forms: function, local, and for;
plus the implicit global variables.

In 5.1 you can use setfenv() to manipulate the implicit global binding of
unrelated code, which effectively allows you to define new binding forms
such as the OO class helpers we discussed last week, and Miles's import
function. You get some of the EDSL flavour Scheme gets from macros, at the
cost of poor lexical discipline.

5.2 follows a stricter lexical discipline in which the global environment
of some code can only be changed with assignment to _ENV by other code in
the scope of the same declaration of _ENV. This means any user of a custom
binding form has to explicitly mention _ENV. So some EDSLs are inevitably
rather more ugly in 5.2 than in 5.1.

I wonder if a little bit of syntactic sugar here would make _ENV more
palatable. The original "in exp do block end" is not quite flexible
enough. Perhaps an abbreviation for "function (_ENV) block end" would do
the trick.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Biscay: Northerly 4 or 5, occasionally 6 at first in west. Moderate or rough,
occasionally very rough at first in west. Showers dying out. Mainly good.