lua-users home
lua-l archive

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


On Wed, Jun 17, 2015 at 2:21 PM, Robert Virding <rvirding@gmail.com> wrote:
When I first implement luerl, Lua in erlang, I didn't realise this and just overwrote the variables. But eventually I read the manual a bit more closely and got it right. I find personally find it both logical and illogical, coming from other languages I would expect the compiler to complain.

Well, consider the following C program:

    #include <stdio.h>

    int main(void)
    {
      int foo = 25;
      {
     int foo = 100;
     printf("foo == %d\n", foo);
      }
      printf("foo == %d\n", foo);

      return 0;
    }

Would you expect an error? Perhaps you don't actually know C, if you're steeped in awesome things like Lua and Erlang, but this totally valid C. In fact, it outputs what you would expect, if you were familiar with Lua local scoping with blocks:

    foo == 100
    foo == 25

You can't redefine a var in the same scope like you can with Lua or say Go's := operator, but you can definitely redefine variables within a scope in lots of languages.
--
Brigham Toskin