lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Dirk Laurie <dpl@sun.ac.za> writes:

> On Sun, Jan 09, 2011 at 04:51:00PM +0200, David Kastrup wrote:
>> Dirk Laurie <dpl@sun.ac.za> writes:
>> 
>> > 6. insert(a,b) does not do the same as insert(a,b,nil).  This 
>> >     behaviour would not be possible for a function of three arguments
>> >     written in Lua itself.
>> 
>> Huh?
>> 
>> function arity(...)
>>   return select('#',...)
>> end
>> print(arity(1,2),arity(1,2,nil))
>> 
>> returns
>> 
>> 2       3
>> 
> By 'a function of three arguments' I mean a function starting with e.g.
>
>     function f(a,b,c)

A "function of three arguments" receives three arguments by demand and
coercion.  It is somewhat silly to complain that it can't distinguish
getting a different number.

I don't see that a function starting with e.g.

      function f(a,b,...)

can't be used as a function of two _or_ three arguments perfectly well.
You could try arguing that f in this case does not raise an error when
called with 4 arguments.  But neither does insert, or any Lua function.
Spurious arguments are always allowed and ignored.

-- 
David Kastrup