June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
64
Task/Ternary-logic/Elena/ternary-logic.elena
Normal file
64
Task/Ternary-logic/Elena/ternary-logic.elena
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import extensions.
|
||||
import system'routines.
|
||||
import system'collections.
|
||||
|
||||
sealed class Trit
|
||||
{
|
||||
bool _value.
|
||||
|
||||
bool = _value.
|
||||
|
||||
sealed explicit object:v
|
||||
[
|
||||
_value := v bool.
|
||||
]
|
||||
|
||||
type<Trit> equivalent : b
|
||||
= _value equal(b bool) \ back:nil.
|
||||
|
||||
type<Trit> inverted
|
||||
= _value inverted \ back:nil.
|
||||
|
||||
type<Trit> and : b
|
||||
[
|
||||
if ($nil == _value)
|
||||
[
|
||||
^ b and:nil \ back:nil.
|
||||
];
|
||||
[
|
||||
^ _value and:$(b bool) \ back:nil.
|
||||
]
|
||||
]
|
||||
|
||||
type<Trit> or : b
|
||||
[
|
||||
if ($nil == _value)
|
||||
[
|
||||
^ b or:nil \ back:nil.
|
||||
];
|
||||
[
|
||||
^ _value or:$(b bool) \ back:nil.
|
||||
]
|
||||
]
|
||||
|
||||
type<Trit> implies : b
|
||||
= $self inverted; or:b.
|
||||
|
||||
literal = _value literal \ back:"maybe".
|
||||
}
|
||||
|
||||
program =
|
||||
[
|
||||
list<Trit> values := (true, nil, false).
|
||||
values forEach(:left)
|
||||
[
|
||||
console printLine("¬",left," = ", left inverted).
|
||||
values forEach(:right)
|
||||
[
|
||||
console printLine(left, " & ", right, " = ", left && right).
|
||||
console printLine(left, " | ", right, " = ", left || right).
|
||||
console printLine(left, " → ", right, " = ", left implies:right).
|
||||
console printLine(left, " ≡ ", right, " = ", left equivalent:right).
|
||||
].
|
||||
].
|
||||
].
|
||||
27
Task/Ternary-logic/Julia/ternary-logic.julia
Normal file
27
Task/Ternary-logic/Julia/ternary-logic.julia
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
@enum Trit False Maybe True
|
||||
const trits = (False, Maybe, True)
|
||||
|
||||
Base.:!(a::Trit) = a == False ? True : a == Maybe ? Maybe : False
|
||||
∧(a::Trit, b::Trit) = a == b == True ? True : (a, b) ∋ False ? False : Maybe
|
||||
∨(a::Trit, b::Trit) = a == b == False ? False : (a, b) ∋ True ? True : Maybe
|
||||
⊃(a::Trit, b::Trit) = a == False || b == True ? True : (a, b) ∋ Maybe ? Maybe : False
|
||||
≡(a::Trit, b::Trit) = (a, b) ∋ Maybe ? Maybe : a == b ? True : False
|
||||
|
||||
println("Not (!):")
|
||||
println(join(@sprintf("%10s%s is %5s", "!", t, !t) for t in trits))
|
||||
println("And (∧):")
|
||||
for a in trits
|
||||
println(join(@sprintf("%10s ∧ %5s is %5s", a, b, a ∧ b) for b in trits))
|
||||
end
|
||||
println("Or (∨):")
|
||||
for a in trits
|
||||
println(join(@sprintf("%10s ∨ %5s is %5s", a, b, a ∨ b) for b in trits))
|
||||
end
|
||||
println("If Then (⊃):")
|
||||
for a in trits
|
||||
println(join(@sprintf("%10s ⊃ %5s is %5s", a, b, a ⊃ b) for b in trits))
|
||||
end
|
||||
println("Equivalent (≡):")
|
||||
for a in trits
|
||||
println(join(@sprintf("%10s ≡ %5s is %5s", a, b, a ≡ b) for b in trits))
|
||||
end
|
||||
47
Task/Ternary-logic/Perl-6/ternary-logic.pl6
Normal file
47
Task/Ternary-logic/Perl-6/ternary-logic.pl6
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Implementation:
|
||||
enum Trit <Foo Moo Too>;
|
||||
|
||||
sub prefix:<¬> (Trit $a) { Trit(1-($a-1)) }
|
||||
|
||||
sub infix:<∧> (Trit $a, Trit $b) is equiv(&infix:<*>) { $a min $b }
|
||||
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)) }
|
||||
|
||||
# Testing:
|
||||
say '¬';
|
||||
say "Too {¬Too}";
|
||||
say "Moo {¬Moo}";
|
||||
say "Foo {¬Foo}";
|
||||
|
||||
sub tbl (&op,$name) {
|
||||
say '';
|
||||
say "$name Too Moo Foo";
|
||||
say " ╔═══════════";
|
||||
say "Too║{op Too,Too} {op Too,Moo} {op Too,Foo}";
|
||||
say "Moo║{op Moo,Too} {op Moo,Moo} {op Moo,Foo}";
|
||||
say "Foo║{op Foo,Too} {op Foo,Moo} {op Foo,Foo}";
|
||||
}
|
||||
|
||||
tbl(&infix:<∧>, '∧');
|
||||
tbl(&infix:<∨>, '∨');
|
||||
tbl(&infix:<⇒>, '⇒');
|
||||
tbl(&infix:<≡>, '≡');
|
||||
|
||||
say '';
|
||||
say 'Precedence tests should all print "Too":';
|
||||
say ~(
|
||||
Foo ∧ Too ∨ Too ≡ Too,
|
||||
Foo ∧ (Too ∨ Too) ≡ Foo,
|
||||
Too ∨ Too ∧ Foo ≡ Too,
|
||||
(Too ∨ Too) ∧ Foo ≡ Foo,
|
||||
|
||||
¬Too ∧ Too ∨ Too ≡ Too,
|
||||
¬Too ∧ (Too ∨ Too) ≡ ¬Too,
|
||||
Too ∨ Too ∧ ¬Too ≡ Too,
|
||||
(Too ∨ Too) ∧ ¬Too ≡ ¬Too,
|
||||
|
||||
Foo ∧ Too ∨ Foo ⇒ Foo ≡ Too,
|
||||
Foo ∧ Too ∨ Too ⇒ Foo ≡ Foo,
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue