Better eval.lisp
This commit is contained in:
25
eval.lisp
25
eval.lisp
@@ -45,31 +45,20 @@ and the maximum number (or nil for infinity) as a second value."
|
|||||||
(t (error "unknown operator: ~S" oper))))
|
(t (error "unknown operator: ~S" oper))))
|
||||||
|
|
||||||
(defun logical-xor (&rest args)
|
(defun logical-xor (&rest args)
|
||||||
"Logical xor (not equal) each argument in turn with its following argument.
|
"Logical xor (not equal) each argument in turn with its following argument."
|
||||||
NOTE: This is NOT a macro, there is no short circuit evaluation (all arguments
|
(eql 1 (count-if #'identity args)))
|
||||||
are evaluated no matter what)."
|
|
||||||
(loop with result = nil
|
|
||||||
for arg in args do
|
|
||||||
(setq result (not (eq result arg)))
|
|
||||||
finally (return result)))
|
|
||||||
|
|
||||||
(defun logical-and (&rest args)
|
(defun logical-and (&rest args)
|
||||||
"Logical and (all true).
|
"Logical and (all true)."
|
||||||
NOTE: This is NOT a macro, there is no short circuit evaluation (all arguments
|
(every #'identity args))
|
||||||
are evaluated no matter what)."
|
|
||||||
(not (member nil args)))
|
|
||||||
|
|
||||||
(defun logical-or (&rest args)
|
(defun logical-or (&rest args)
|
||||||
"Logical or (one or more true).
|
"Logical or (one or more true)."
|
||||||
NOTE: This is NOT a macro, so there is no short circuit evaluation (all
|
(some #'identity args))
|
||||||
arguments are evaluated no matter what)."
|
|
||||||
(not (not (member t args))))
|
|
||||||
|
|
||||||
(defun logical-implies (prop1 prop2)
|
(defun logical-implies (prop1 prop2)
|
||||||
"Evaluate the logical implies operation on PROP1 and PROP2. That is \"if
|
"Evaluate the logical implies operation on PROP1 and PROP2. That is \"if
|
||||||
PROP1, then PROP2\".
|
PROP1, then PROP2\"."
|
||||||
NOTE: This is NOT a macro, so there is no short circuit evaluation (all
|
|
||||||
arguments are evaluated no matter what)."
|
|
||||||
(if prop1 ;; only if first is true
|
(if prop1 ;; only if first is true
|
||||||
prop2 ;; eval second
|
prop2 ;; eval second
|
||||||
t)) ;; otherwise, just return true
|
t)) ;; otherwise, just return true
|
||||||
|
|||||||
Reference in New Issue
Block a user