enum begin False = -1, Maybe, True end local Chrs = {"F", "M", "T"} class trit public v function __construct(v) assert(v == False or v == Maybe or v == True, "Invalid argument.") self.v = v end function __bnot() return new trit(-self.v) end function __band(other) return (self.v < other.v) ? (self) : other end function __bor(other) return (self.v > other.v) ? (self) : other end function __shr(other) return (-self.v > other.v) ? (~self) : other end function eqv(other) return new trit(self.v * other.v) end function __tostring() return Chrs[self.v + 2] end end local trits = {new trit(True), new trit(Maybe), new trit(False)} print("not") print("-------") for trits as t do print($" {t} | {~t}") end print("\nand | T M F") print("-------------") for trits as t do io.write($" {t} | ") for trits as u do io.write($"{tostring(t & u)} ") end print() end print("\nor | T M F") print("-------------") for trits as t do io.write($" {t} | ") for trits as u do io.write($"{tostring(t | u)} ") end print() end print("\nimp | T M F") print("-------------") for trits as t do io.write($" {t} | ") for trits as u do io.write($"{tostring(t >> u)} ") end print() end print("\neqv | T M F") print("-------------") for trits as t do io.write($" {t} | ") for trits as u do io.write($"{tostring(t:eqv(u))} ") end print() end