Skip to content

Commit f2c9ba0

Browse files
committed
Add xor operation to the base standard library
Should xor have a corresponding infix operator?
1 parent 5100e20 commit f2c9ba0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: Stdlib/Data/Bool/Base.juvix

+6
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,11 @@ or (a b : Bool) : Bool := a || b;
3737
--- Logical conjunction.
3838
and (a b : Bool) : Bool := a && b;
3939

40+
--- Logical exclusive or.
41+
xor : Bool -> Bool -> Bool
42+
| true true := false
43+
| false flase := false
44+
| _ _ := true;
45+
4046
builtin assert
4147
assert (x : Bool) : Bool := x;

Diff for: test/Test/Prelude.juvix

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import Test.JuvixUnit open;
44
import Stdlib.Prelude open;
55

66
tests : List Test :=
7-
[testCase "And" (assertEqual "and works as expected" (and true false) false)];
7+
[
8+
testCase "And" (assertEqual "and works as expected" (and true false) false);
9+
testCase
10+
"Xor"
11+
(assertEqual "and works as expected" (xor true false) (xor false true));
12+
testCase
13+
"Xor-2"
14+
(assertEqual "and works as expected" (xor false false) (xor true true));
15+
];
816

917
suite : TestSuite := testSuite "Prelude" tests;
1018

0 commit comments

Comments
 (0)