lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/01/10 22:20, Nevin Flanagan wrote:
[...]
> I think this is a big part of it. I do, however, think there is a place for taking code you're not responsible for authoring and constraining it into an environment of your choosing. What appeals to me about the "closure clone" concept is that it allows you to do this in many cases, but doesn't force other code built around the original function from also using the new behavior; since the function with the new environment is a separate object, other code will keep its original copy with the previous environment.

I've also just spotted another huge advantage of in: it's reentrant.

local function chain(n, t)
  if (n > 0) then
    in t do
      local nextt = chain(n-1, {})
      next = nextt
    end
  end
  return t
end c = chain

...actually behaves the way one would expect. Using setfenv() in this
would have really weird behavious (because the call to chain changes
where the assignment to next is done).

I bring this up because it's not documented (I think it's just assumed
- --- Principle Of Least Surprise) and I'm not sure anyone's spotted it yet.

- -- 
???? ?????????????? ????? http://www.cowlark.com ?????
?
? "Under communism, man exploits man. Under capitalism, it's just the
? opposite." --- John Kenneth Galbrith
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFLTQO+f9E0noFvlzgRAmxiAJ930AeTzMtGFKGy2xmkrM8irWijnQCeJrCH
Twedd2X0jpdAMmes/I8gLrs=
=UEet
-----END PGP SIGNATURE-----