Ternary logic: Difference between revisions

Ternary logic en BASIC256
(Added Arturo implementation)
(Ternary logic en BASIC256)
Line 647:
false Ternary_equiv maybe = maybe
false Ternary_equiv false = true</pre>
 
 
=={{header|BASIC256}}==
{{trans|Liberty BASIC}}
<lang lb>
global tFalse, tDontKnow, tTrue
tFalse = 0
tDontKnow = 1
tTrue = 2
 
print "Nombres cortos y largos para valores lógicos ternarios:"
for i = tFalse to tTrue
print shortName3$(i); " "; longName3$(i)
next i
print
 
print "Funciones de parámetro único"
print "x"; " "; "=x"; " "; "not(x)"
for i = tFalse to tTrue
print shortName3$(i); " "; shortName3$(i); " "; shortName3$(not3(i))
next i
print
 
print "Funciones de doble parámetro"
print "x";" ";"y";" ";"x AND y";" ";"x OR y";" ";"x EQ y";" ";"x XOR y"
for a = tFalse to tTrue
for b = tFalse to tTrue
print shortName3$(a); " "; shortName3$(b); " ";
print shortName3$(and3(a,b)); " "; shortName3$(or3(a,b));" ";
print shortName3$(eq3(a,b)); " "; shortName3$(xor3(a,b))
next b
next a
end
 
function and3(a,b)
if a < b then return a else return b
end function
 
function or3(a,b)
if a > b then return a else return b
end function
 
function eq3(a,b)
begin case
case a = tDontKnow or b = tDontKnow
return tDontKnow
case a = b
return tTrue
else
return tFalse
end case
end function
 
function xor3(a,b)
return not3(eq3(a,b))
end function
 
function not3(b)
return 2-b
end function
 
function shortName3$(i)
shortName3$ = mid("F?T", i+1, 1)
end function
 
function longName3$(i)
begin case
case i = 1
return "Don't know"
case i = 2
return "False"
else
return "True"
end case
end function
 
</lang>
{{out}}
<pre>
Igual que la entrada de Liberty BASIC.
</pre>
 
 
=={{header|BBC BASIC}}==
2,143

edits