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
case a of
terTrue: terNot := terFalse;
terTrue: terNot := terFalse;
terMayBe: terNot := terMayBe;
terMayBe: terNot := terMayBe;
terFalse: terNot := terTrue;
terFalse: terNot := terTrue;
end;
end;
end;
end;


function terAnd (a, b: trit): trit;
function terAnd (a, b: trit): trit;
begin
begin
terAnd := terMayBe;
terAnd := terMayBe;
if (a = terFalse) or (b = terFalse) then
if (a = terFalse) or (b = terFalse) then
terAnd := terFalse
terAnd := terFalse
else
else
if (a = terTrue) and (b = terTrue) then
if (a = terTrue) and (b = terTrue) then
terAnd := terTrue;
terAnd := terTrue;
end;
end;


function terOr (a, b: trit): trit;
function terOr (a, b: trit): trit;
begin
begin
terOr := terMayBe;
terOr := terMayBe;
if (a = terTrue) or (b = terTrue) then
if (a = terTrue) or (b = terTrue) then
terOr := terTrue
terOr := terTrue
else
else
if (a = terFalse) and (b = terFalse) then
if (a = terFalse) and (b = terFalse) then
terOr := terFalse;
terOr := terFalse;
end;
end;


function terEquals (a, b: trit): trit;
function terEquals (a, b: trit): trit;
begin
begin
if a = b then
terEquals := terMayBe;
if a = b then
terEquals := terTrue
terEquals := terTrue
else
else
if a <> b then
if a <> b then
terEquals := terFalse;
terEquals := terFalse;
if (a = terMayBe) or (b = terMayBe) then
terEquals := terMayBe;
end;
end;


function terIfThen (a, b: trit): trit;
function terIfThen (a, b: trit): trit;
begin
begin
terIfThen := terMayBe;
terIfThen := terMayBe;
if (a = terTrue) or (b = terFalse) then
if (a = terTrue) or (b = terFalse) then
terIfThen := terTrue
terIfThen := terTrue
else
else
if (a = terFalse) and (b = terTrue) then
if (a = terFalse) and (b = terTrue) then
terIfThen := terFalse;
terIfThen := terFalse;
end;
end;


Line 1,735: Line 1,735:
begin
begin
case a of
case a of
terTrue: terToStr := 'True ';
terTrue: terToStr := 'True ';
terMayBe: terToStr := 'Maybe';
terMayBe: terToStr := 'Maybe';
terFalse: terToStr := 'False';
terFalse: terToStr := 'False';
end;
end;
end;
end;



begin
begin
Line 1,794: Line 1,792:


EQUAL True Maybe False
EQUAL True Maybe False
True True False False
True True Maybe False
Maybe False True False
Maybe Maybe Maybe Maybe
False False False True
False False Maybe True


</pre>
</pre>