From cc3bc44687d12c528e4c1151d64a5b76db7c4f96 Mon Sep 17 00:00:00 2001 From: mariari Date: Thu, 7 Nov 2024 14:10:42 +0800 Subject: [PATCH] Add xor operation to the base standard library Should xor have a corresponding infix operator? --- Stdlib/Data/Bool/Base.juvix | 6 ++++++ test/Test/Prelude.juvix | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Stdlib/Data/Bool/Base.juvix b/Stdlib/Data/Bool/Base.juvix index 75fe8a63..0f0a1ceb 100644 --- a/Stdlib/Data/Bool/Base.juvix +++ b/Stdlib/Data/Bool/Base.juvix @@ -37,5 +37,11 @@ or (a b : Bool) : Bool := a || b; --- Logical conjunction. and (a b : Bool) : Bool := a && b; +--- Logical exclusive or. +xor : Bool -> Bool -> Bool + | true true := false + | false flase := false + | _ _ := true; + builtin assert assert (x : Bool) : Bool := x; diff --git a/test/Test/Prelude.juvix b/test/Test/Prelude.juvix index e0b65989..f2e451a1 100644 --- a/test/Test/Prelude.juvix +++ b/test/Test/Prelude.juvix @@ -4,7 +4,15 @@ import Test.JuvixUnit open; import Stdlib.Prelude open; tests : List Test := - [testCase "And" (assertEqual "and works as expected" (and true false) false)]; + [ + testCase "And" (assertEqual "and works as expected" (and true false) false); + testCase + "Xor" + (assertEqual "and works as expected" (xor true false) (xor false true)); + testCase + "Xor-2" + (assertEqual "and works as expected" (xor false false) (xor true true)); + ]; suite : TestSuite := testSuite "Prelude" tests;