Jump to content

Ternary logic: Difference between revisions

→‎{{header|Pascal}}: fix wrong logic and indentation
(→‎{{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:
 
=={{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);
 
type
trit = (terTrue, terMayBe, terFalse);
 
function terNot (a: trit): trit;
begin
case a of
terTrue: terNot := terFalse;
terMayBe: terNot := terMayBe;
terFalse: terNot := terTrue;
end;
end;
 
function terAnd (a, b: trit): trit;
begin
terAnd := terMayBe;
if (a = terFalse) or (b = terFalse) then
terAnd := terFalse
else
if (a = terTrue) and (b = terTrue) then
terAnd := terTrue;
end;
 
function terOr (a, b: trit): trit;
begin
terOr := terMayBe;
if (a = terTrue) or (b = terTrue) then
terOr := terTrue
else
if (a = terFalse) and (b = terFalse) then
terOr := terFalse;
end;
 
function terEquals (a, b: trit): trit;
begin
if a = b then
terEquals := terMayBe;
if a = b then
terEquals := terTrue
else
if a <> b then
terEquals := terFalse;
if (a = terMayBe) or (b = terMayBe) then
terEquals := terMayBe;
end;
 
function terIfThen (a, b: trit): trit;
begin
terIfThen := terMayBe;
if (a = terTrue) or (b = terFalse) then
terIfThen := terTrue
else
if (a = terFalse) and (b = terTrue) then
terIfThen := terFalse;
end;
 
Line 1,735:
begin
case a of
terTrue: terToStr := 'True ';
terMayBe: terToStr := 'Maybe';
terFalse: terToStr := 'False';
end;
end;
 
 
begin
Line 1,794 ⟶ 1,792:
 
EQUAL True Maybe False
True True FalseMaybe False
Maybe FalseMaybe TrueMaybe FalseMaybe
False False FalseMaybe True
 
</pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.