lua-users home
lua-l archive

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


On Sat, Apr 18, 2009 at 8:31 AM, steve donovan wrote:
> Penlight is a set of pure Lua libraries designed to make some common
> tasks easier and more standard.

"memoize" [1] is a handy function.  The basic form that appears in a
number of my own modules is the one in[2].

  function memoize(func)
    return setmetatable({}, {
      __index = function(self, k) local v = func(k); self[k] = v; return v end,
      __call = function(self, k) return self[k] end
    })
  end

Also note that Metalua implements its own standard library[3-4], which
has some overlap with Penlight.  There could be some collaboration
there.  I know Fabien advocates against the reinvent-the-wheel thing,
and having your work incorporated into Metalua would be a good thing
for Penlight's promotion.

[1] http://lua-users.org/wiki/FuncTables
[2] http://lua-users.org/wiki/CodeGeneration
[3] http://metalua.luaforge.net/manual005.html
[4] http://lua-users.org/wiki/StandardLibraries