lua-users home
lua-l archive

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


Ok, after re-reading my mail not only the english is awful, but I even mangled the snippet: "b()" is "f()" like this

    x=1
    function f()
      x=2 --which x is this?
    end
    f()
    print (x)

Jorge

On 08/07/2014 07:50 PM, Jorge Visca wrote:
On 07/08/14 14:06, Roberto Ierusalimschy wrote:
1) Local by default is a mess.

Incredibly, even if you don't have globals!

The shortest explanation I've found is the following example:

   x=1
   function f()
     x=2 --which x is this?
   end
   b()
   print (x)

With local by default, there are two possibles interpretation for the
inner x variable. If it means a new x, how can you actually change the
outer x? If it means the outer x, then it is not actually a local. If
you have such a "local" in you function, and someone uses a equally
named variable in an enclosing scope they will collide.