Ternary logic: Difference between revisions

Content added Content deleted
mNo edit summary
 
Line 3,463: Line 3,463:
=={{header|langur}}==
=={{header|langur}}==
{{trans|Go}}
{{trans|Go}}
<syntaxhighlight lang="langur"># borrowing null for "maybe"
<syntaxhighlight lang="langur">
# borrowing null for "maybe"
val .trSet = [false, null, true]
val trSet = [false, null, true]


val .and = fn .a, .b: switch[and] .a, .b {
val tand = fn a, b: switch[and] a, b {
case true, null:
case true, null:
case null, true:
case null, true:
case null: null
case null: null
default: .a and .b
default: a and b
}
}


val .or = fn .a, .b: switch[and] .a, .b {
val tor = fn a, b: switch[and] a, b {
case false, null:
case false, null:
case null, false:
case null, false:
case null: null
case null: null
default: .a or .b
default: a or b
}
}


val .imply = fn .a, .b: if(.a nor .b: not? .a; .b)
val imply = fn a, b: if(a nor b: not? a; b)


# formatting function for the result values
# formatting function for the result values
# replacing null with "maybe"
# replacing null with "maybe"
# using left alignment of 5 code points
# using left alignment of 5 code points
val .F = fn .r: "{{nn [.r, "maybe"]:-5}}"
val F = fn r: "{{nn([r, "maybe"]):-5}}"


writeln "a not a"
writeln "a not a"
for .a in .trSet {
for a in trSet {
writeln "{{.a:fn F}} {{not? .a:fn F}}"
writeln "{{a:fn F}} {{not? a:fn F}}"
}
}


writeln "\na b a and b"
writeln "\na b a and b"
for .a in .trSet {
for a in trSet {
for .b in .trSet {
for b in trSet {
writeln "{{.a:fn F}} {{.b:fn F}} {{.and(.a, .b):fn F}}"
writeln "{{a:fn F}} {{b:fn F}} {{tand(a, b):fn F}}"
}
}
}
}


writeln "\na b a or b"
writeln "\na b a or b"
for .a in .trSet {
for a in trSet {
for .b in .trSet {
for b in trSet {
writeln "{{.a:fn F}} {{.b:fn F}} {{.or(.a, .b):fn F}}"
writeln "{{a:fn F}} {{b:fn F}} {{tor(a, b):fn F}}"
}
}
}
}


writeln "\na b a implies b"
writeln "\na b a implies b"
for .a in .trSet {
for a in trSet {
for .b in .trSet {
for b in trSet {
writeln "{{.a:fn F}} {{.b:fn F}} {{.imply(.a, .b):fn F}}"
writeln "{{a:fn F}} {{b:fn F}} {{imply(a, b):fn F}}"
}
}
}
}


writeln "\na b a eq b"
writeln "\na b a eq b"
for .a in .trSet {
for a in trSet {
for .b in .trSet {
for b in trSet {
writeln "{{.a:fn F}} {{.b:fn F}} {{.a ==? .b:fn F}}"
writeln "{{a:fn F}} {{b:fn F}} {{a ==? b:fn F}}"
}
}
}
}