Ternary logic: Difference between revisions

m
→‎{{header|Perl 6}}: Combine blocks to make runnable code for ease of automated testing
m (→‎{{header|Perl 6}}: Combine blocks to make runnable code for ease of automated testing)
Line 3,583:
false 1</pre>
=={{header|Perl 6}}==
{{Works with|rakudo|20162018.0703}}
 
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:
<lang perl6>enum Trit <Foo Moo Too>;
 
sub prefix:<¬> (Trit $a) { Trit(1-($a-1)) }
Line 3,593 ⟶ 3,596:
 
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>
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 "Too {¬Too}";
say "Moo {¬Moo}";
Line 3,632 ⟶ 3,634:
Foo ∧ Too ∨ Too ⇒ Foo ≡ Foo,
);</lang>
 
{{out}}
<pre>¬
10,339

edits