lua-users home
lua-l archive

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


<boringalert> I'm returning to a topic that has been well chewed
over on this list many times.
</boringalert>

Many if not all of us have small, almost trivial utilities that we include
in most of our programs. Here is one of mine. It is given only to focus
the discussion, not because I think it is in any way unusually good.

local clone
clone = function(tbl)
  if type(tbl) ~= 'table' then return tbl end
  local t={}
  for k,v in pairs(tbl) do t[k]=clone(v) end
  return t
end

Please do not point out particular defects of the code, such as that
the original table may have had duplicate subtables but the clone
does not. It is given _only to focus the discussion_, as an example
of the size and nature of the little utilities that I am talking about.

The questions that IMO bear revisiting every now and then are:

1. Is it a good thing for a newbie to write such utilities from scratch,
in the process learning some subtleties of Lua, rather than grab
them off a standardish package? (Niklaus Wirth omitted an
exponentiation operator from Pascal for mainly this reason).

2. Should the Lua standard libraries supply any non-basic table
routines?
2a. (This is a specific version of the previous point.) Why do you
think did the Lua team supply none such beyond `pairs` and
a library that operates on sequences?

3. Should we make any attempt to standardize the name and
functionality of such routines, in the hope that one day a Lua
standard library, widely accepted by the community, will emerge?
3a. Should libraries like stdlib, Penlight and org.conman make
any effort to become compatible in terms of naming and
functionality?