From d28c008c5dc537c244c41277e6d54a7e1578937b Mon Sep 17 00:00:00 2001 From: paladin Date: Mon, 15 Jun 2026 12:35:50 +0100 Subject: [PATCH] Reimplemented nexus and classes ADTs. --- main.lua | 109 ++++++++++++++++++------------------------------------- 1 file changed, 36 insertions(+), 73 deletions(-) diff --git a/main.lua b/main.lua index cbc3b88..a63d4a0 100644 --- a/main.lua +++ b/main.lua @@ -1,77 +1,40 @@ --- A unique group -local classes = {} -classes.input = {} -classes.output = {} -local function class() - return {} +local ID = 1 +local c = {} +setmetatable(c,{__call = function(c) + local this = {} + c[this] = {} + return this +end}) +c.i = {} +c.o = {} +c.next = c() +for char in ("abcdefghijklmnopqrstuvwxyz $;"):match(".") do + c.i[char] = c() end -classes.after = class() -classes.next = class() -classes.chain = class() -classes.inside = class() -for char in "$abcdefghijklmnopqrstuvwxyz ":gmatch(".") do - classes.input[char] = class() - classes.output[char] = class() - end - --- Relation of a class holdin a value between nexus of symbolic index -local function nex(class,v,...) - local this = {class = class, value = value, up = {}, at = {},...} - for index,item in ipairs({...}) do - this.at[item] = index - table.insert(item.up,this) - end - return this +local function n(class,data,...) + local this = {up = {},class = class,data = data} + table.insert(c[class],this) + return this end - --- implication trees, but what about the actions behind them? and things that don't really exist? --- imagination allows things that aren't possible to be possible in our heads at least. --- an implication tree in a sense. - -local function update(root) - -- Objective: find nexus pieces that relate to cookies - -- find the cookies and try to build classes about them - -- try to crunch those classes and find similarities - -end - -local function action(root) - -- Objective: build hypothetical scenarios from nexus - -- the ones with output classes are most preferred since they can be acted upon - -end - --- Main loop -local previous_chain +local i = {} +setmetatable(i,{__call = function(i,this) + +end}) +local prev while true do - local input = io.read() - if input == "end" then return end - local actor - if input:match("^~") then - actor = input.output - input = input:match("[^#]*") - elseif input:match("[^@]*") then - actor = input.input - input = input:match("[^P]*") - elseif input:match("^#") then - print("null") - return - elseif input:match("^;") then - previous_chain = null + prev = n(c[";"],ID,nil) + local input = io.read() + local mode,input = io.read():match("([#P])(.*)") + local t = ({["$"]=c.i,["#"]=c.o})[mode] + if t then + for char in input:match(".") do + if t[char] then + local this = n(t[char],ID,nil) + n(t.next,ID,prev,this) + i(this) + prev = this + end end - local previous - local chain = nex(classes.chain,1) - if previous_chain then - nex(classes.after,1,previous_chain,chain) - end - for char in input:gmatch(".") do - if classes[char] then - local object = nex(actor[char],1) - nex(classes.inside,1,object,chain) - if previous then nex(classes.next,1,previous,object) end - previous = object - end - end - update(chain) - action(chain) -end \ No newline at end of file + end + prev = n(t[";"],ID,nil) +end