Ternary logic: Difference between revisions
m
→{{header|Perl 6}}: Combine blocks to make runnable code for ease of automated testing
Thundergnat (talk | contribs) 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|
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:
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)) }
▲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:
say "Too {¬Too}";
say "Moo {¬Moo}";
Line 3,632 ⟶ 3,634:
Foo ∧ Too ∨ Too ⇒ Foo ≡ Foo,
);</lang>
{{out}}
<pre>¬
|