lua-users home
lua-l archive

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


Hi David and all,

On Sat, Feb 26, 2011 at 4:42 AM, David Kastrup <dak@gnu.org> wrote:
> 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.

For historical reasons,

  http://www.lua.org/manual/4.0/manual.html#lua_getn

and because

  function mypack (...) return {n=select("#", ...), ...} end
  function myunpack (T) return unpack(T, 1, T.n) end  -- 5.1

is shorter than:

  function mypack (...) return {["#"]=select("#", ...), ...} end
  function myunpack (T) return unpack(T, 1, T["#"]) end  -- 5.1

Of course we can also use:

  function mypack (...) return {Dracula=select("#", ...), ...} end
  function myunpack (T) return unpack(T, 1, T.Dracula) end  -- 5.1

because "#" is better than "n", but "Dracula" is better than "#"... It
is easier to search for all the occurrence of "Dracula" in a program
and replace them for some other name if we find another better name
(how many times you have used "Dracula" in your programs, eh?!) than
to do that for "n" or "#"... 8-)

  Cheers,
    Eduardo Ochs
    eduardoochs@gmail.com
    http://angg.twu.net/