--- lam.list local list = {} local util = require "util" local types = require "types" table.unpack = table.unpack or unpack list.Null = setmetatable({}, { __type = "Null", __tostring = function(self) return "()" end, }) list.isNull = function (x) return x == list.Null end list.List = function (tbl) local function tolist (base, items) if #items == 0 then return base end return tolist ( types.Cons(table.remove(items), base), items ) end return tolist(list.Null, tbl) end list.isList = function (x) if list.isNull(x) then return true elseif types.isa(x, "Pair") then return list.isList(x[2]) else return false end end list.fold1 = function (fn, seed, lis) if list.isNull(lis) then return seed end return list.fold1(fn, fn(seed, lis[1]), lis[2]) end --- return list