[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: explicit mode
- From: Nagaev Boris <bnagaev@...>
- Date: Fri, 13 May 2016 09:32:04 +0300
On Fri, May 13, 2016 at 12:58 AM, Soni L. <fakedme@gmail.com> wrote:
>
>
> On 12/05/16 04:51 PM, Nagaev Boris wrote:
>>
>> On Wed, May 11, 2016 at 9:26 AM, Viacheslav Usov <via.usov@gmail.com>
>> wrote:
>>>
>>> On Tue, May 10, 2016 at 7:00 PM, Sean Conner <sean@conman.org> wrote:
>>>
>>>> I think he wants something like:
>>>>
>>>> global x -- define a global x
>>>> function foo(a,b)
>>>> local c -- define a local variable
>>>> c = a * b + y -- compile time error---y not defined
>>>> end
>>>
>>>
>>> I am not exactly sure. The more I think about it, the more convinced I am
>>> that, in principle, it is enough for the explicit mode to remove the
>>> current
>>> syntactic sugar that converts anything not defined as a local into a
>>> global
>>> table lookup. This will eliminate the silent promotion of mistyped locals
>>> into globals, and the need to type the ugly _ENV will always be a
>>> reminder
>>> for users that globals are not exactly cheap.
>>>
>>> But I am not going to insist on that.
>>>
>>> Cheers,
>>> V.
>>>
>>
>> Hi,
>>
>> you can use luacheck as a library and filter warnings to keep only
>> warnings about global variables. For example, you don't want "unused
>> variable" warning, but want only "using global" warnings - it is easy
>> to implement.
>>
>> By the way, without any globals, how can one use normal globals like
>> "print", "math" etc? Always declaring them is annoying.
>>
>>
> _ENV.globalname?
>
And you can use `withing` discussed in other thread to write this:
local print, math withing(_ENV)
print(math.sin(0.0))
Less mess than declaring "global print, math" for each function.
--
Best regards,
Boris Nagaev
- References:
- explicit mode, Viacheslav Usov
- Re: explicit mode, Luiz Henrique de Figueiredo
- Re: explicit mode, Viacheslav Usov
- Re: explicit mode, Chris Berardi
- Re: explicit mode, Viacheslav Usov
- Re: explicit mode, Michal Kottman
- Re: explicit mode, Viacheslav Usov
- Re: explicit mode, Soni L.
- Re: explicit mode, Sean Conner
- Re: explicit mode, Viacheslav Usov
- Re: explicit mode, Nagaev Boris
- Re: explicit mode, Soni L.