#!/usr/bin/env -Slua -i local cip = require "automaton" local x = "abcdefghijklm opqrstuvxyz" local state = cip(x) local history = {} local format = require "format" local function log (value) table.insert(history, {previous=state, value=value}) end function back () local entry = table.remove(history) if not entry then io.stderr:write("already at the earliest revision\n") return end state = entry.previous return state end function init (data) if data then x = data end state = cip(x) history = {} return state end function show () print(state) end function c () log(0) state = state:pivot() return state end function up () log(1) state = state:up() return state end function down () log(3) state = state:down() return state end function left () log(4) state = state:left() return state end function right () log(2) state = state:right() return state end function flush () local values = {} for _, v in ipairs(history) do table.insert(values, v) end io.write("{", format.csv(values), "}\n") history = {} end