RosettaCodeData/Task/Ternary-logic/Run-BASIC/ternary-logic.basic

59 lines
1.5 KiB
Plaintext

testFalse = 0 ' F
testDoNotKnow = 1 ' ?
testTrue = 2 ' T
print "Short and long names for ternary logic values"
for i = testFalse to testTrue
print shortName3$(i);" ";longName3$(i)
next i
print
print "Single parameter functions"
print "x";" ";"=x";" ";"not(x)"
for i = testFalse to testTrue
print shortName3$(i);" ";shortName3$(i);" ";shortName3$(not3(i))
next
print
print "Double parameter fuctions"
html "<table border=1><TR align=center bgcolor=wheat><TD>x</td><td>y</td><td>x AND y</td><td>x OR y</td><td>x EQ y</td><td>x XOR y</td></tr>"
for a = testFalse to testTrue
for b = testFalse to testTrue
html "<TR align=center><td>"
html shortName3$(a); "</td><td>";shortName3$(b); "</td><td>"
html shortName3$(and3(a,b));"</td><td>";shortName3$(or3(a,b)); "</td><td>"
html shortName3$(eq3(a,b)); "</td><td>";shortName3$(xor3(a,b));"</td></tr>"
next
next
html "</table>"
function and3(a,b)
and3 = min(a,b)
end function
function or3(a,b)
or3 = max(a,b)
end function
function eq3(a,b)
eq3 = testFalse
if a = tDontKnow or b = tDontKnow then eq3 = tDontKnow
if a = b then eq3 = testTrue
end function
function xor3(a,b)
xor3 = not3(eq3(a,b))
end function
function not3(b)
not3 = 2-b
end function
'------------------------------------------------
function shortName3$(i)
shortName3$ = word$("F ? T", i+1)
end function
function longName3$(i)
longName3$ = word$("False,Don't know,True", i+1, ",")
end function