lua-users home
lua-l archive

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


On Wed, Dec 16, 2009 at 22:21, Petite Abeille <petite_abeille@mac.com> wrote:
>
> On Dec 16, 2009, at 9:08 PM, Cosmin Apreutesei wrote:
>
>>> f( 'foo', nil, 'bar', nil )
>>
>> That n is exactly what I would've scrapped.
>
> You cannot just scrap that as it tells unpack how long your list of argument is. Without it, you could never properly unpack arguments with nils.
>
> Consider:
>
> print( #{ 'a', nil, 'b', nil } )
>
>> 1
>
> Therefore:
>
> unpack( { 'a', nil, 'b', nil } ) would pass only the first parameter if not told otherwise.
>
> So:
>
> f( 'a', nil, 'b', nil ) != f( unpack( { 'a', nil, 'b', nil } ) ) = f( 'a' )
> f( 'a', nil, 'b', nil ) = f( unpack( { 'a', nil, 'b', nil }, 1, 4 ) )
>

Ugh, yes, you're right, I got that part out of a larger context[1]
where in my mind # was also defined for sparse arrays. Sorry for the
confusion. I'd still make f() equivalent to f(nil) even without the
alignment of varargs and arrays length.

[1] http://lua-users.org/wiki/CosminApreutesei