Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
114
Task/Ternary-logic/Seed7/ternary-logic.seed7
Normal file
114
Task/Ternary-logic/Seed7/ternary-logic.seed7
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const type: trit is new enum
|
||||
False, Maybe, True
|
||||
end enum;
|
||||
|
||||
# Enum types define comparisons (=, <, >, <=, >=, <>) and
|
||||
# the conversions ord and conv.
|
||||
|
||||
const func string: str (in trit: aTrit) is
|
||||
return [] ("False", "Maybe", "True")[succ(ord(aTrit))];
|
||||
|
||||
enable_output(trit); # Allow writing trit values
|
||||
|
||||
const array trit: tritNot is [] (True, Maybe, False);
|
||||
const array array trit: tritAnd is [] (
|
||||
[] (False, False, False),
|
||||
[] (False, Maybe, Maybe),
|
||||
[] (False, Maybe, True ));
|
||||
const array array trit: tritOr is [] (
|
||||
[] (False, Maybe, True ),
|
||||
[] (Maybe, Maybe, True ),
|
||||
[] (True, True, True ));
|
||||
const array array trit: tritXor is [] (
|
||||
[] (False, Maybe, True ),
|
||||
[] (Maybe, Maybe, Maybe),
|
||||
[] (True, Maybe, False));
|
||||
const array array trit: tritImplies is [] (
|
||||
[] (True, True, True ),
|
||||
[] (Maybe, Maybe, True ),
|
||||
[] (False, Maybe, True ));
|
||||
const array array trit: tritEquiv is [] (
|
||||
[] (True, Maybe, False),
|
||||
[] (Maybe, Maybe, Maybe),
|
||||
[] (False, Maybe, True ));
|
||||
|
||||
const func trit: not (in trit: aTrit) is
|
||||
return tritNot[succ(ord(aTrit))];
|
||||
|
||||
const func trit: (in trit: aTrit1) and (in trit: aTrit2) is
|
||||
return tritAnd[succ(ord(aTrit1))][succ(ord(aTrit2))];
|
||||
|
||||
const func trit: (in trit: aTrit1) and (ref func trit: aTrit2) is func
|
||||
result
|
||||
var trit: res is False;
|
||||
begin
|
||||
if aTrit1 = True then
|
||||
res := aTrit2;
|
||||
elsif aTrit1 = Maybe and aTrit2 <> False then
|
||||
res := Maybe;
|
||||
end if;
|
||||
end func;
|
||||
|
||||
const func trit: (in trit: aTrit1) or (in trit: aTrit2) is
|
||||
return tritOr[succ(ord(aTrit1))][succ(ord(aTrit2))];
|
||||
|
||||
const func trit: (in trit: aTrit1) or (ref func trit: aTrit2) is func
|
||||
result
|
||||
var trit: res is True;
|
||||
begin
|
||||
if aTrit1 = False then
|
||||
res := aTrit2;
|
||||
elsif aTrit1 = Maybe and aTrit2 <> True then
|
||||
res := Maybe;
|
||||
end if;
|
||||
end func;
|
||||
|
||||
$ syntax expr: .().xor.() is -> 15;
|
||||
const func trit: (in trit: aTrit1) xor (in trit: aTrit2) is
|
||||
return tritImplies[succ(ord(aTrit1))][succ(ord(aTrit2))];
|
||||
|
||||
const func trit: (in trit: aTrit1) -> (in trit: aTrit2) is
|
||||
return tritImplies[succ(ord(aTrit1))][succ(ord(aTrit2))];
|
||||
|
||||
const func trit: (in trit: aTrit1) == (in trit: aTrit2) is
|
||||
return tritEquiv[succ(ord(aTrit1))][succ(ord(aTrit2))];
|
||||
|
||||
const func trit: rand (in trit: low, in trit: high) is
|
||||
return trit conv (rand(ord(low), ord(high)));
|
||||
|
||||
# Begin of test code
|
||||
|
||||
var trit: operand1 is False;
|
||||
var trit: operand2 is False;
|
||||
|
||||
const proc: writeTable (ref func trit: tritExpr, in string: name) is func
|
||||
begin
|
||||
writeln;
|
||||
writeln(" " <& name rpad 7 <& " | False Maybe True");
|
||||
writeln("---------+---------------------");
|
||||
for operand1 range False to True do
|
||||
write(" " <& operand1 rpad 7 <& " | ");
|
||||
for operand2 range False to True do
|
||||
write(tritExpr rpad 7);
|
||||
end for;
|
||||
writeln;
|
||||
end for;
|
||||
end func;
|
||||
|
||||
const proc: main is func
|
||||
begin
|
||||
writeln(" not" rpad 8 <& " | False Maybe True");
|
||||
writeln("---------+---------------------");
|
||||
write(" | ");
|
||||
for operand1 range False to True do
|
||||
write(not operand1 rpad 7);
|
||||
end for;
|
||||
writeln;
|
||||
writeTable(operand1 and operand2, "and");
|
||||
writeTable(operand1 or operand2, "or");
|
||||
writeTable(operand1 xor operand2, "xor");
|
||||
writeTable(operand1 -> operand2, "->");
|
||||
writeTable(operand1 == operand2, "==");
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue