Ternary logic: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: Combine blocks to make runnable code for ease of automated testing)
Line 3,583: Line 3,583:
false 1</pre>
false 1</pre>
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{Works with|rakudo|2016.07}}
{{Works with|rakudo|2018.03}}

Implementation:
The precedence of each operator is specified as equivalent to an existing operator. We've taken the liberty of using a double arrow for implication, to avoid confusing it with <tt>⊃</tt>, (U+2283 SUPERSET OF).
<lang perl6>enum Trit <Foo Moo Too>;

<lang perl6># Implementation:
enum Trit <Foo Moo Too>;


sub prefix:<¬> (Trit $a) { Trit(1-($a-1)) }
sub prefix:<¬> (Trit $a) { Trit(1-($a-1)) }
Line 3,593: Line 3,596:


sub infix:<⇒> (Trit $a, Trit $b) is equiv(&infix:<..>) { ¬$a max $b }
sub infix:<⇒> (Trit $a, Trit $b) is equiv(&infix:<..>) { ¬$a max $b }
sub infix:<≡> (Trit $a, Trit $b) is equiv(&infix:<eq>) { Trit(1 + ($a-1) * ($b-1)) }</lang>
sub infix:<≡> (Trit $a, Trit $b) is equiv(&infix:<eq>) { Trit(1 + ($a-1) * ($b-1)) }
The precedence of each operator is specified as equivalent to an existing operator. We've taken the liberty of using a double arrow for implication, to avoid confusing it with <tt>⊃</tt>, (U+2283 SUPERSET OF).


# Testing:
To test, we use this code:
<lang perl6>say '¬';
say '¬';
say "Too {¬Too}";
say "Too {¬Too}";
say "Moo {¬Moo}";
say "Moo {¬Moo}";
Line 3,632: Line 3,634:
Foo ∧ Too ∨ Too ⇒ Foo ≡ Foo,
Foo ∧ Too ∨ Too ⇒ Foo ≡ Foo,
);</lang>
);</lang>

{{out}}
{{out}}
<pre>¬
<pre>¬