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))))
|
||||
|
||||
(defun logical-xor (&rest args)
|
||||
"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
|
||||
are evaluated no matter what)."
|
||||
(loop with result = nil
|
||||
for arg in args do
|
||||
(setq result (not (eq result arg)))
|
||||
finally (return result)))
|
||||
"Logical xor (not equal) each argument in turn with its following argument."
|
||||
(eql 1 (count-if #'identity args)))
|
||||
|
||||
(defun logical-and (&rest args)
|
||||
"Logical and (all true).
|
||||
NOTE: This is NOT a macro, there is no short circuit evaluation (all arguments
|
||||
are evaluated no matter what)."
|
||||
(not (member nil args)))
|
||||
"Logical and (all true)."
|
||||
(every #'identity args))
|
||||
|
||||
(defun logical-or (&rest args)
|
||||
"Logical or (one or more true).
|
||||
NOTE: This is NOT a macro, so there is no short circuit evaluation (all
|
||||
arguments are evaluated no matter what)."
|
||||
(not (not (member t args))))
|
||||
"Logical or (one or more true)."
|
||||
(some #'identity args))
|
||||
|
||||
(defun logical-implies (prop1 prop2)
|
||||
"Evaluate the logical implies operation on PROP1 and PROP2. That is \"if
|
||||
PROP1, then PROP2\".
|
||||
NOTE: This is NOT a macro, so there is no short circuit evaluation (all
|
||||
arguments are evaluated no matter what)."
|
||||
PROP1, then PROP2\"."
|
||||
(if prop1 ;; only if first is true
|
||||
prop2 ;; eval second
|
||||
t)) ;; otherwise, just return true
|
||||
|
||||
Reference in New Issue
Block a user