local I = 1 local c = setmetatable({},{ __call = function(c,class,data,...) local new = {} -- todo: use a better data structure; recycle nexus new.implies = {} -- Table of all dependency nexus of this class: it.items[0] == c setmetatable(new,c) return new end }) c.d = c() -- depend c.s = c() -- solve c.c = c() -- commit c.h = c() -- cookie heuristic local function h(it) -- Find and return the data value of the first heuristic unit super-nexus of this object for item,index in pairs(it.index) do if item.class = c.h then return item.data end end end local function s(it) -- todo: use some sort of heuristic here like A* local options = {it} while true do table.sort(branches,function(a,b) return h(a) > h(b) end) for depends in pairs(it.class.implies) do depends. end break end end local n = setmetatable({},{ __call = function(n,class,data,...) local new = {} setmetatable(new,n) new.class = class table.insert(class.instances,class) new.data = data new.items = {...} for index,item in pairs(new.items) do item.index[new] = index end new.index = {} s(new) return new end }) c.next = c() c.in = {} c.out = {} c.text = {} c.cookie = c() for char in ("abcdefghijklmnopqrstuvwxyz "):match(".") do c.in[char] = c() c.out[char] = c() end local previous = n(c(),I) while true do local input = io.read() for command in input:gmatch([^@]*) do local name,text = command:match("(%a*)%s*(.*)") if name == "cookie" then local cookie = n(c.cookie,I) n(c.next,I,previous,cookie) previous = cookie else local mode if name == "in" or name == "" then mode = c.in elseif name == "out" then mode = c.out else error(string.format("Unknown command '@%s'",name)) end for char in text:match(".") do if mode[char] then local object = n(mode[char],I) n(c.next,I,previous,object) previous = object end end end end end