lua-users home
lua-l archive

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

I have a rather big collection of higher-order functions that are used
to improve and evaluate an assignment of papers to reviewers.  I was
struggling to find a good way to do this when it suddenly hit
me that I could adapt the module technology.  My code looks like this:

  local function amodule(asst, papernums)
    asst.pinned = asst.pinned or table.of_tables { }
    asst.papers = asst.papers or table.of_tables { }
    asst.reviewed_by = asst.reviewed_by or table.of_tables { }
    local pinned, papers, reviewed_by = asst.pinned, asst.papers, asst.reviewed_by

    local M = { }
    setmetatable(M, { __index = _G })
    setfenv(1, M)
    ... large collection of definitions as for global variables ...

    return M

The use of the code then becomes very simple:

  local function go(asst, papernums, do_pc)
    local A = amodule(asst, papernums)
    A.extend(stdrtabs.coarseh, papernums)
    A.balance(stdrtabs.finesth, stdrtabs.finesth)
    if do_pc then A.pc_does_not_review_pc() end
    return asst, A.xc_counts

I thought others might enjoy using this trick as well.