Make xor return single true inputs
The documentation should now be correct (#1214).
This commit is contained in:
parent
7a4a2ca668
commit
9ca7f49c88
10
NEWS
10
NEWS
@ -1,3 +1,13 @@
|
|||||||
|
Changes from 0.12.1
|
||||||
|
|
||||||
|
[ Language Changes ]
|
||||||
|
* xor: If exactly one argument is true, return it
|
||||||
|
|
||||||
|
Changes from 0.12.0
|
||||||
|
|
||||||
|
[ Bug Fixes ]
|
||||||
|
* Allow installation without Git
|
||||||
|
|
||||||
Changes from 0.11.0
|
Changes from 0.11.0
|
||||||
|
|
||||||
This release brings some quite significant changes on the language and as a
|
This release brings some quite significant changes on the language and as a
|
||||||
|
@ -1713,20 +1713,15 @@ xor
|
|||||||
|
|
||||||
.. versionadded:: 0.12.0
|
.. versionadded:: 0.12.0
|
||||||
|
|
||||||
``xor`` is used in logical expressions to perform exclusive or. It takes two
|
``xor`` performs the logical operation of exclusive OR. It takes two arguments.
|
||||||
parameters. It returns ``True`` if only of the parameters is ``True``. In all
|
If exactly one argument is true, that argument is returned. If neither is true,
|
||||||
other cases ``False`` is returned. Example usage:
|
the second argument is returned (which will necessarily be false). Otherwise,
|
||||||
|
when both arguments are true, the value ``False`` is returned.
|
||||||
|
|
||||||
.. code-block:: clj
|
.. code-block:: clj
|
||||||
|
|
||||||
=> (xor True False)
|
=> [(xor 0 0) (xor 0 1) (xor 1 0) (xor 1 1)]
|
||||||
True
|
[0, 1, 1, False]
|
||||||
|
|
||||||
=> (xor True True)
|
|
||||||
False
|
|
||||||
|
|
||||||
=> (xor [] [0])
|
|
||||||
True
|
|
||||||
|
|
||||||
|
|
||||||
yield
|
yield
|
||||||
|
@ -481,8 +481,9 @@
|
|||||||
|
|
||||||
(defn xor [a b]
|
(defn xor [a b]
|
||||||
"Perform exclusive or between two parameters"
|
"Perform exclusive or between two parameters"
|
||||||
(or (and a (not b))
|
(if (and a b)
|
||||||
(and b (not a))))
|
False
|
||||||
|
(or a b)))
|
||||||
|
|
||||||
(def *exports*
|
(def *exports*
|
||||||
'[*map accumulate butlast calling-module-name chain coll? combinations
|
'[*map accumulate butlast calling-module-name chain coll? combinations
|
||||||
|
@ -1019,12 +1019,23 @@
|
|||||||
|
|
||||||
(defn test-xor []
|
(defn test-xor []
|
||||||
"NATIVE: test the xor macro"
|
"NATIVE: test the xor macro"
|
||||||
(let [xor-both-true (xor True True)
|
|
||||||
xor-both-false (xor False False)
|
; Test each cell of the truth table.
|
||||||
xor-true-false (xor True False)]
|
(assert (is (xor False False) False))
|
||||||
(assert (= xor-both-true False))
|
(assert (is (xor False True) True))
|
||||||
(assert (= xor-both-false False))
|
(assert (is (xor True False) True))
|
||||||
(assert (= xor-true-false True))))
|
(assert (is (xor True True) False))
|
||||||
|
|
||||||
|
; Same thing, but with numbers.
|
||||||
|
(assert (is (xor 0 0) 0))
|
||||||
|
(assert (is (xor 0 1) 1))
|
||||||
|
(assert (is (xor 1 0) 1))
|
||||||
|
(assert (is (xor 1 1) False))
|
||||||
|
|
||||||
|
; Of two distinct false values, the second is returned.
|
||||||
|
(assert (is (xor False 0) 0))
|
||||||
|
(assert (is (xor 0 False) False)))
|
||||||
|
|
||||||
|
|
||||||
(defn test-if-return-branching []
|
(defn test-if-return-branching []
|
||||||
"NATIVE: test the if return branching"
|
"NATIVE: test the if return branching"
|
||||||
|
Loading…
Reference in New Issue
Block a user