Merge pull request #872 from tuturto/xor
Add exclusive or logical operator
This commit is contained in:
commit
3eb6001852
@ -1489,6 +1489,27 @@ expands to:
|
||||
Section :ref:`using-gensym`
|
||||
|
||||
|
||||
xor
|
||||
---
|
||||
|
||||
.. versionadded:: 0.12.0
|
||||
|
||||
``xor`` is used in logical expressions to perform exclusive or. It takes two
|
||||
parameters. It returns ``True`` if only of the parameters is ``True``. In all
|
||||
other cases ``False`` is returned. Example usage:
|
||||
|
||||
.. code-block:: clj
|
||||
|
||||
=> (xor True False)
|
||||
True
|
||||
|
||||
=> (xor True True)
|
||||
False
|
||||
|
||||
=> (xor [] [0])
|
||||
True
|
||||
|
||||
|
||||
yield
|
||||
-----
|
||||
|
||||
|
@ -463,6 +463,11 @@
|
||||
(hyify (. value __name__))
|
||||
(except [] (string value))))))
|
||||
|
||||
(defn xor [a b]
|
||||
"Perform exclusive or between two parameters"
|
||||
(or (and a (not b))
|
||||
(and b (not a))))
|
||||
|
||||
(def *exports*
|
||||
'[*map accumulate butlast calling-module-name chain coll? combinations
|
||||
compress cons cons? count cycle dec distinct disassemble drop drop-last
|
||||
@ -472,4 +477,4 @@
|
||||
last list* macroexpand macroexpand-1 map merge-with multicombinations name
|
||||
neg? nil? none? nth numeric? odd? partition permutations pos? product range
|
||||
read read-str remove repeat repeatedly rest reduce second some string
|
||||
string? symbol? take take-nth take-while tee zero? zip zip-longest])
|
||||
string? symbol? take take-nth take-while xor tee zero? zip zip-longest])
|
||||
|
@ -927,6 +927,15 @@
|
||||
(assert (= a 1)))
|
||||
|
||||
|
||||
(defn test-xor []
|
||||
"NATIVE: test the xor macro"
|
||||
(let [xor-both-true (xor true true)
|
||||
xor-both-false (xor false false)
|
||||
xor-true-false (xor true false)]
|
||||
(assert (= xor-both-true false))
|
||||
(assert (= xor-both-false false))
|
||||
(assert (= xor-true-false true))))
|
||||
|
||||
(defn test-if-return-branching []
|
||||
"NATIVE: test the if return branching"
|
||||
; thanks, algernon
|
||||
|
Loading…
Reference in New Issue
Block a user