[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Forward function declarations - relocal command
- From: David Favro <lua@...>
- Date: Tue, 20 Nov 2012 06:03:31 -0500
On 11/19/2012 07:58 AM, Roberto Ierusalimschy wrote:
>> How do other people deal with forward declarations?
> I tend to define any function before using it, so I only need a forward
> declaration when the code has indirect recursion.
But the relocal keyword could apply to more than just function
definitions, it could simplify the instance of defining multiple local
variables for multiple return values in an inner scope when one of the
return values is wanted in an outer scope, e.g.:
local rv1;
repeat
local rv2;
rv1, rv2 = foo();
until rv2;
-- use rv1 here...
Now becomes:
local rv1;
repeat
relocal rv1, rv2 = foo();
until rv2;
-- use rv1 here...
I'm not necessarily for the new keyword, but the need for the extra
"local rv2" line comes up a lot for me, and bothers me. I suppose that
one could just declare rv2 local in the outer scope along with rv1 --
I've seen it noted that space for local storage is almost never an
issue, but this seems like a sloppy habit, I think that names and the
consequent reference to storage should be limited to the innermost scope
in which they are used.
Is there some other idiom to accomplish this in the current language
with a nicer look than my first snippet?
-- David