6

I see that = is great for "comparing" more than two (numerical) arguments, e.g., (= 1 1 1). But then eq, eql, and equal all only allow two arguments. And nesting is nonsense, i.e., the inner eq returns only nil or t to compare the next argument. Any way to get more than two things (non-number) compared with a comparison predicate? For example:

(= (+ (* constant input-1) input-2)
   (+ (* constant input-2) input-1)
   (* constant output))

This, BTW, is a definition of a linear system. But then it's awkward to not be able to directly compare more than two conditions at a time.

Drew
  • 75,699
  • 9
  • 109
  • 225
147pm
  • 2,907
  • 1
  • 18
  • 39
  • 1
    [ Now that I actually read your question (duh!): ] A good way would be to submit a patch that extends those predicates, as was done for `=`, `<=`, etc... – Stefan Nov 25 '15 at 19:47

1 Answers1

4

I'm not aware of a package that does that but you can easily define an auxiliary function to help you.

(defun sortedp (predicate &rest args)
  "Test whether ARGS are in increasing order according to PREDICATE.
That is, test whether (PREDICATE (nth 0 ARGS) (nth 1 ARGS)),
\(PREDICATE (nth 0 ARGS) (nth 1 ARGS)), etc. are all true.
PREDICATE is typically an order relation (`<=', `string-lessp', ...) or
an equivalence relation (`=', `eq', `equal', ...)."
  (let ((ret t))
    (while (and ret (consp (cdr args)))
      (if (funcall predicate (car args) (car (cdr args)))
          (setq args (cdr args))
        (setq ret nil)))
    ret))

(sortedp #'equal '(1) '(1) '(1))  ==>  t
(sortedp #'equal '() '(1) '(1))  ==>  nil
(sortedp #'string-lessp "a" "ab" "ac")  ==>  t
(sortedp #'string-lessp "a" "ab" "a" "ac")  ==>  nil