46 lines
2.2 KiB
Text
46 lines
2.2 KiB
Text
INSTALL @lib$ + "CLASSLIB"
|
|
|
|
REM Create a ternary class:
|
|
DIM trit{tor, tand, teqv, tnot, tnor, s, v}
|
|
DEF PRIVATE trit.s (t&) LOCAL t$():DIM t$(2):t$()="FALSE","MAYBE","TRUE":=t$(t&)
|
|
DEF PRIVATE trit.v (t$) = INSTR("FALSE MAYBE TRUE", t$) DIV 6
|
|
DEF trit.tnot (t$) = FN(trit.s)(2 - FN(trit.v)(t$))
|
|
DEF trit.tor (a$,b$) LOCAL t:t=FN(trit.v)(a$)ORFN(trit.v)(b$):=FN(trit.s)(t+(t>2))
|
|
DEF trit.tnor (a$,b$) = FN(trit.tnot)(FN(trit.tor)(a$,b$))
|
|
DEF trit.tand (a$,b$) = FN(trit.tnor)(FN(trit.tnot)(a$),FN(trit.tnot)(b$))
|
|
DEF trit.teqv (a$,b$) = FN(trit.tor)(FN(trit.tand)(a$,b$),FN(trit.tnor)(a$,b$))
|
|
PROC_class(trit{})
|
|
|
|
PROC_new(mytrit{}, trit{})
|
|
|
|
REM Test it:
|
|
PRINT "Testing NOT:"
|
|
PRINT "NOT FALSE = " FN(mytrit.tnot)("FALSE")
|
|
PRINT "NOT MAYBE = " FN(mytrit.tnot)("MAYBE")
|
|
PRINT "NOT TRUE = " FN(mytrit.tnot)("TRUE")
|
|
|
|
PRINT '"Testing OR:"
|
|
PRINT "FALSE OR FALSE = " FN(mytrit.tor)("FALSE","FALSE")
|
|
PRINT "FALSE OR MAYBE = " FN(mytrit.tor)("FALSE","MAYBE")
|
|
PRINT "FALSE OR TRUE = " FN(mytrit.tor)("FALSE","TRUE")
|
|
PRINT "MAYBE OR MAYBE = " FN(mytrit.tor)("MAYBE","MAYBE")
|
|
PRINT "MAYBE OR TRUE = " FN(mytrit.tor)("MAYBE","TRUE")
|
|
PRINT "TRUE OR TRUE = " FN(mytrit.tor)("TRUE","TRUE")
|
|
|
|
PRINT '"Testing AND:"
|
|
PRINT "FALSE AND FALSE = " FN(mytrit.tand)("FALSE","FALSE")
|
|
PRINT "FALSE AND MAYBE = " FN(mytrit.tand)("FALSE","MAYBE")
|
|
PRINT "FALSE AND TRUE = " FN(mytrit.tand)("FALSE","TRUE")
|
|
PRINT "MAYBE AND MAYBE = " FN(mytrit.tand)("MAYBE","MAYBE")
|
|
PRINT "MAYBE AND TRUE = " FN(mytrit.tand)("MAYBE","TRUE")
|
|
PRINT "TRUE AND TRUE = " FN(mytrit.tand)("TRUE","TRUE")
|
|
|
|
PRINT '"Testing EQV (similar to EOR):"
|
|
PRINT "FALSE EQV FALSE = " FN(mytrit.teqv)("FALSE","FALSE")
|
|
PRINT "FALSE EQV MAYBE = " FN(mytrit.teqv)("FALSE","MAYBE")
|
|
PRINT "FALSE EQV TRUE = " FN(mytrit.teqv)("FALSE","TRUE")
|
|
PRINT "MAYBE EQV MAYBE = " FN(mytrit.teqv)("MAYBE","MAYBE")
|
|
PRINT "MAYBE EQV TRUE = " FN(mytrit.teqv)("MAYBE","TRUE")
|
|
PRINT "TRUE EQV TRUE = " FN(mytrit.teqv)("TRUE","TRUE")
|
|
|
|
PROC_discard(mytrit{})
|