[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [CFD] Local functions for Lua 4.1
- From: James Hearn <james.hearn@...>
- Date: Wed, 21 Nov 2001 16:04:05 -0700
Modifying the function statement to allow the use of a 'local' or 'global'
prefix makes sense to me in the case ET gives. It brings the connotation of
function declaration (local function foo() end) more in line with variable
declaration (local foo = 10), while still avoiding the can of worms which
would be making all variables local by default.
Once possible negative effect is that it (local function foo() end) would be
semantically different from (local foo = function() end) in the context of
the described function, which may be nonobvious. On the other hand, the only
option with the function statement currently is (function foo() end) which
leaves no choice to have the function be created locally, unlike vanilla
variable declarations which allow the use of a scoping specifier.
The only pitfall I can see is that now one would have to differentiate
between (local function foo() foo() end) and (local foo = function () foo()
end), which do different things. The nested foo() in the first example calls
itself recursively, while the nested foo in the second example calls some
global foo. The first would instead be semantically identical to (local foo
function foo() foo() end).
I'm not a language designer, but this seems to make sense to me. It
introduces a new subtle difference between the different ways of creating a
function, which could cause bugs; however, some would consider the current
behavior a bug. It's a matter of picking one's poison.
I'm sure I've missed something here. Feel free to enlighten me :)