lua-users home
lua-l archive

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


> It's ultimately a question of "why not?" Lua's scopes are bound to blocks,
> and a block is any structure that can contain one or more statements.
> There's no good reason to have a different type of block for an if...end
> statement than there is for a do...end statement. It lets the same rules
> define the syntax and the scopes.

I tend to think of 'local' as being an action that creates a variable.
Each time we execute that action, we create a new variable. Now,
consider this code:

  if false then local x = 1 end
  print(x)

It seems weird to me that 'print' would be using a variable that was
not created. (In this case, it was also not initialized.)

By bounding them to inner blocks, we ensure we can only use a
variable that was properly created.

-- Roberto
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org