Ternary logic: Difference between revisions
Content added Content deleted
(→{{header|Pascal}}: Marked incorrect as the EQUAL table if it should be the equivalent table of the task description, is wrong) |
(→{{header|Pascal}}: fix wrong logic and indentation) |
||
Line 1,677: | Line 1,677: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
{{incorrect|Pascal|The EQUAL table if it should be the '''equivalent''' table of the task description, is wrong.}} |
|||
<lang pascal>Program TernaryLogic (output); |
<lang pascal>Program TernaryLogic (output); |
||
type |
type |
||
trit = (terTrue, terMayBe, terFalse); |
trit = (terTrue, terMayBe, terFalse); |
||
function terNot (a: trit): trit; |
function terNot (a: trit): trit; |
||
begin |
begin |
||
case a of |
|||
terTrue: terNot := terFalse; |
|||
terMayBe: terNot := terMayBe; |
|||
terFalse: terNot := terTrue; |
|||
end; |
|||
end; |
end; |
||
function terAnd (a, b: trit): trit; |
function terAnd (a, b: trit): trit; |
||
begin |
begin |
||
terAnd := terMayBe; |
|||
if (a = terFalse) or (b = terFalse) then |
|||
terAnd := terFalse |
terAnd := terFalse |
||
else |
|||
if (a = terTrue) and (b = terTrue) then |
|||
terAnd := terTrue; |
|||
end; |
end; |
||
function terOr (a, b: trit): trit; |
function terOr (a, b: trit): trit; |
||
begin |
begin |
||
terOr := terMayBe; |
|||
if (a = terTrue) or (b = terTrue) then |
|||
terOr := terTrue |
terOr := terTrue |
||
else |
|||
if (a = terFalse) and (b = terFalse) then |
|||
terOr := terFalse; |
|||
end; |
end; |
||
function terEquals (a, b: trit): trit; |
function terEquals (a, b: trit): trit; |
||
begin |
begin |
||
⚫ | |||
⚫ | |||
⚫ | |||
terEquals := terTrue |
terEquals := terTrue |
||
else |
|||
if a <> b then |
|||
terEquals := terFalse; |
|||
if (a = terMayBe) or (b = terMayBe) then |
|||
⚫ | |||
end; |
end; |
||
function terIfThen (a, b: trit): trit; |
function terIfThen (a, b: trit): trit; |
||
begin |
begin |
||
terIfThen := terMayBe; |
|||
if (a = terTrue) or (b = terFalse) then |
|||
terIfThen := terTrue |
terIfThen := terTrue |
||
else |
|||
if (a = terFalse) and (b = terTrue) then |
|||
terIfThen := terFalse; |
|||
end; |
end; |
||
Line 1,735: | Line 1,735: | ||
begin |
begin |
||
case a of |
case a of |
||
terTrue: terToStr := 'True '; |
|||
terMayBe: terToStr := 'Maybe'; |
|||
terFalse: terToStr := 'False'; |
|||
end; |
|||
end; |
end; |
||
begin |
begin |
||
Line 1,794: | Line 1,792: | ||
EQUAL True Maybe False |
EQUAL True Maybe False |
||
True True |
True True Maybe False |
||
Maybe |
Maybe Maybe Maybe Maybe |
||
False False |
False False Maybe True |
||
</pre> |
</pre> |