[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: sunday afternoon whishlist
- From: "Stuart P. Bentley" <stuart@...>
- Date: Wed, 02 Jun 2010 09:22:18 -0700
On Tue, 11 May 2010 11:17:39 -0700, Henk Boom <henk@henk.ca> wrote:
On 11 May 2010 12:50, Roberto Ierusalimschy <roberto@inf.puc-rio.br>
wrote:
Unfortunately it is not true ;) The expression "#..." does make sense
and has a clear meaning, consistent with #f(x) (and with -f(x), -...,
etc.). And there are no plans to change varargs in 5.2.
One thing I wonder is why functions accept any number of arguments by
default, instead of requiring an exact number (this is a pet peeve of
mine,
since I often call functions with the wrong number of arguments by
accident). Functions which require a variable number of arguments (or
optional arguments) could still use ... to get them.
henk
Because Lua doesn't limit the language to accommodate errors. It's better
to be able to do things like use functions as iterators that weren't
designed to take all the parameters passed by the generic for.
If you find you're having a lot of trouble with functions taking the wrong
number of parameters, consider using this:
function argchecked(f, numargs)
return function(...)
if select('#',...)==numargs then f(...)
else error(string.format(
"%i arguments expected, got %i",
numargs,select('#',...))) end
end
end