[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Consistency with Parameters & Return Values
- From: Eric Ries <eries@...>
- Date: Sat, 21 Dec 2002 13:27:39 -0800 (PST)
One advantage would be compile time checking, if that's what you want. Of
course, there isn't much checking of this sort elsewhere in lua.
Eric
On Sat, 21 Dec 2002, Björn De Meyer wrote:
> Peter Hill wrote:
> >
> > One thing that seems asymmetrical to me in Lua is that functions may take
> > either a fixed or variable number of arguments, while the return values are
> > always variable.
>
> /snip
>
> I fail to see any problem. If you want your function to return a fixed
> number
> of values, then write it so. If you want to return a variable amount of
> results,
> then the builtin function unpack() of Lua 5 and a table will help you.
>
> For example, in Lua 5 beta you can say:
>
> function varres(nres)
> t = {};
> for n = 1,nres,1 do t[n] = n; end;
> return unpack(t)
> end
>
> print(varres(1))
> 1
> print(varres(3))
> 1 2 3
> print(varres(7))
> 1 2 3 4 5 6 7
>
> You could even say: return a,b,unpack(optresults)
> To return both a fixed and a variable amount of arguments.
>
> So I see no reason for the change you propose.
>
> --
> "No one knows true heroes, for they speak not of their greatness." --
> Daniel Remar.
> Björn De Meyer
> bjorn.demeyer@pandora.be
>
>