0

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)
Drew
  • 75,699
  • 9
  • 109
  • 225
ebpa
  • 7,319
  • 26
  • 53
  • 1
    While not directly addressing your question, you might find [this apples-and-oranges page](https://www.emacswiki.org/emacs/ApplesAndOranges) 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

1 Answers1

0

There is no such idiom in Lisp.

Your code is fine though.

sds
  • 5,928
  • 20
  • 39