[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Redefining locals
- From: "Bilyk, Alex" <ABilyk@...>
- Date: Thu, 11 Nov 2004 15:03:46 -0800
Yeah, I see what you mean. Guess I would agree with
local f,g
function g() f() end
function f() g() end
being a good compromise. It does seem odd to me that 'local' would create a slot in the same scope when one just like it has already been defined. I wonder if this has been done intentionally or is it really unintended result of keeping things simple. I think the latter is the case and now a bunch ot people got dependent on it.
Alex.
-----Original Message-----
From: Mark Hamburg [mailto:mhamburg@adobe.com]
Sent: Thursday, November 11, 2004 1:53 PM
To: Lua list
Subject: Re: Redefining locals
With globals, there is only one global variable in
a = 1
a = 1
With locals, there are two variables though one might not have wanted there
to be.
The mistake to be caught isn't
local f = 1
< N lines of code >
local function f() end
It's:
local function f() end
Ooh. This needs to be mutually recursive with some function g, so I need to
forward declare f before g:
local f
local function g() f() end
local function f() g() end
(Ignore the infinite recursion in the example code.)
But this last piece of code doesn't do the right thing. It needs to be:
local f
local function g() f() end
f = function() g() end
It will also work as:
local f
local function g() f() end
function f() g() end
This last one seems particularly misleading.
Mark
on 11/11/04 1:28 PM, Bilyk, Alex at ABilyk@maxis.com wrote:
> While eveyone is debating Scheme vs. Lua, the original message questioned the
> usefulness of being able to say
> local a=1
> local a=1
> My thinking is that its no more useful (or problematic for that matter) than
> using globals
> a=1
> a=1
> If one makes mistakes to the tune of
> local f = 1
> <N lines of code>
> local function f() end -- Being unintended!
> Than the same would apply to globals as well.
> f = 1
> <N lines of code>
> function f() end -- Shell we debate whether this should be allowed or why is
> it useful?
> I doesn't seem to me like it would be Lua's responsibility to address this
> particular coding practice. Pointing a loaded gun and one's feet and pulling
> the trigger may be painful but it is not the gun's falt even when done by
> accident.
>
> Just my .02
> Alex