lua-users home
lua-l archive

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


Eduardo Ochs <eduardoochs@gmail.com> writes:

> and that lack of a distinctive name may be one of the reasons why so
> many people fail to realize that vlists are practically first-class
> values... the "practically" is because to store vlists into variables
> we need to pack them, creating tables with an "n" field:
>
>   function mypack (...) return {n=select("#", ...), ...} end
>   function myunpack (T) return       unpack(T, 1, T.n) end  -- 5.1
>   function myunpack (T) return table.unpack(T, 1, T.n) end  -- 5.2
>
>   print(myunpack(mypack()))                  -->
>   print(myunpack(mypack(nil)))               --> nil
>   print(myunpack(mypack(nil, nil)))          --> nil nil
>   print(myunpack(mypack(nil, nil, nil)))     --> nil nil nil
>
> That's it for the moment.
> Cheers,
>   Eduardo Ochs
>   eduardoochs@gmail.com
>   http://angg.twu.net/
>
>
> P.S.: I know that some people hate the idea of using tables with an
> "n" field,

Why don't you use a "#" field instead?  I don't particularly like the
choice of "#" for the select argument, but there seems little point in
inventing another name for the same purpose.

-- 
David Kastrup