lua-users home
lua-l archive

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

2010/1/12 Luiz Henrique de Figueiredo <>
> But I'm feeling 98% sure "in nil do ... end" never will become valid Lua.

It is valid in 5.2 and it forces (at runtime) that the block does not
contain any references to global variables.

  Lua 5.2.0 (work1)  Copyright (C) 1994-2008, PUC-Rio
  > in nil do a=1 end
  stdin:1: attempt to index local '(environment)' (a nil value)

that's the first thing that seems good/cool/useful about the new lexical environments to me...
It does seem to suggest being able to return values though.

a = in nil do
  return "b"

==> this can be done by wrapping it in a closure:
lua-5.2.0-work1/src$ ./lua
Lua 5.2.0 (work1)  Copyright (C) 1994-2008, PUC-Rio
> a = function () in nil do return "a" end end
> =a()

I think this may become a useful new lua idiom.