|_| low-level clear action I seriously need to write a generator for these... |clearing (@table id), @table id| |clearing (@table id)| |clearing (@table row), @table row| |clearing (@table row)| |clearing (pretty print rows iterator), pretty print rows iterator| |clearing (pretty print rows iterator)| |clearing (print number iterator), print number iterator| |clearing (print number iterator)| |_| high-level clear action |clear (@table id)| , clearing (@table id):9007199254740991 |clear (@table row)| , clearing (@table row):9007199254740991 |clear (pretty print rows iterator)| , clearing (pretty print rows iterator):9007199254740991 |clear (print number iterator)| , clearing (print number iterator):9007199254740991 |_| low-level restore from temporary storage action |restoring (pretty print row index), temporary (pretty print row index)| , pretty print row index |restoring (pretty print row index)| |_| low-level move action |moving (@table size) to (pretty print rows iterator), @table size| , pretty print rows iterator |moving (@table size) to (pretty print rows iterator)| |_| low-level copy action |copying (pretty print row index) to (@table row), pretty print row index| , copying (pretty print row index) to (@table row) , temporary (pretty print row index) , @table row |copying (pretty print row index) to (@table row)| , restoring (pretty print row index) |_| high-level move action |move (@table size) to (pretty print rows iterator)| , clear (pretty print rows iterator) , moving (@table size) to (pretty print rows iterator):9007199254740991 |move (@table size) to (print number iterator)| , clear (print number iterator) , moving (@table size) to (print number iterator):9007199254740991 |_| high-level copy action |copy (pretty print row index) to (@table row)| , clear (@table row) , copying (pretty print row index) to (@table row):9007199254740991 |_| Define our tables |#table, singles| , 1st |#table, doubles| , 1st, 2nd |#table, triples| , 1st, 2nd, 3rd |_| Operations to select a table by id Hand written to show a general pattern for this |set (@table id) to (singles) table| @table id:1 |set (@table id) to (doubles) table| @table id:2 |set (@table id) to (triples) table| @table id:3 |select (singles) table| , clear (@table id) , set (@table id) to (singles) table |select (doubles) table| , clear (@table id) , set (@table id) to (doubles) table |select (triples) table| , clear (@table id) , set (@table id) to (triples) table |_| ports for reading the size of a table |#port, on get table size , needs, @get table size , reads, @table id| , @table size, @no such table |#port body, on get table size, lua| if self.tables[table_id] then counters["@table size"] = #self.tables[table_id] else counters["@no such table"] = 1 end |_| Read data from the command line and pump it into a table. |#port, on read singles, needs, @read singles| |#port body, on read singles, lua| local input = io.read("*a") for left, right in input:gmatch("(%d+)") do self.tables:push_row("singles", { ["1st"] = tonumber(left) or 0 } ) end |#port, on read doubles, needs, @read doubles| |#port body, on read doubles, lua| local input = io.read("*a") for left, right in input:gmatch("(%d+),%s*(%d+)") do self.tables:push_row("doubles", { ["1st"] = tonumber(left) or 0 , ["2nd"] = tonumber(right) or 0 } ) end |#port, on read triples, needs, @read triples| |#port body, on read triples, lua| local input = io.read("*a") for left, right in input:gmatch("(%d+),%s*(%d+),%s*(%d+)") do self.tables:push_row("triples", { ["1st"] = tonumber(left) or 0 , ["2nd"] = tonumber(right) or 0 , ["3rd"] = tonumber(right) or 0 } ) end |_| A generic operations over a table |#port, on pretty print row , needs, @pretty print row, , reads, @table id, @table row| |#port body, on pretty print row, lua| local rows = self.tables[table_id] local row = rows[table_row] io.write(rows.name .. " #" .. tostring(table_row) .. ": ") local mapping = self.tables.mappings[rows.name] local assembled_row = {} for key, index in pairs(mapping) do assembled_row[key] = row[index] end pprint(assembled_row) |_| loop to pretty print the rows of any table |pretty print rows| , clear (@table row) , get table size for (pretty print rows) , pretty printing rows |get table size for (pretty print rows)| , @get table size , move (@table size) to (pretty print rows iterator) |pretty printing rows, pretty print rows iterator| , pretty print row index , copy (pretty print row index) to (@table row) , pretty print row , next pretty print rows |pretty printing rows| |pretty print row| , @pretty print row |next pretty print rows| , pretty printing rows |pretty print row index| || 1st: read singles , 2nd: pretty print singles , 3rd: read doubles , 4th: pretty print doubles , 5th: read triples , 6th: pretty print triples |1st: read singles| , @read singles |2nd: pretty print singles| , select (singles) table , pretty print rows |3rd: read doubles| , @read doubles |4th: pretty print doubles| , select (doubles) table , pretty print rows |5th: read triples| , @read triples |6th: pretty print triples| , select (triples) table , pretty print rows