Are there idiomatic boolean comparators in emacs lisp?

Something like:

(my/bool< nil t)
 => t
(my/bool< 1 2)
 => nil

For example, a comparator that returns t if the first argument is nil and the second is truthy (per common association of '0' with 'false' or nil). The convention isn't important; only that it is a comparator and not a simple xor function.

For example, use as a sorting predicate:

(sort '(nil t t nil t nil nil nil t)
      (lambda (a b)
        (and (not a) b)))
 = > (nil nil nil nil nil t t t t)

(sort '(nil 1 5 nil 3 nil nil nil 2)
      (lambda (a b)
        (and (not a) b)))
 => (nil nil nil nil nil 1 5 3 2)
| improve this question | | | | |
  • 1
    While not directly addressing your question, you might find this apples-and-oranges page about combining sort predicates helpful. – Drew Mar 27 '17 at 14:21
  • Great post, @Drew. Component Predicate is a neat pattern; I like it. – ebpa Mar 27 '17 at 16:26

There is no such idiom in Lisp.

Your code is fine though.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.