What boolean/logical convenience functions / macros are available for Emacs Lisp in either the core set of functions or external packages?
I'm interested in just about anything other than the built-in logical operators in and
, or
, not
(null
) and conditional forms (if
, when
, unless
, cond
). To illustrate the sort of convenience functions I have in mind:
Common Lisp has sequence predicates such as some
and every
and other functions like count-if
(in cl-lib
as cl-some
, cl-every
, and cl-count-if
respectively). When used with an identity function, (cl-some #'identity my-list)
it performs a logical OR over elements in the list and (cl-every #'identity my-list)
performs a logical AND over elements in the list. These are convenient and are nearly ideal, but aren't purely logical functions because they require a predicate that is applied to each element. These functions are available in cl-lib
.
and
and or
conceptually fill the same niche, but clearly note that their use is limited because they are implemented as macros. Expressions such as (apply #'and my-list)
are not possible.
I have reviewed the list of ~1089 built-in Elisp functions and macros and only know of two relevant convenience functions. booleanp
checks if the argument's value is t
or nil
and not
is an alias for null
.
There are also numerous boolean vector convenience functions that are a part of Elisp, but as far as I can tell are only suitable for binary manipulation.
@Dan points out the use of memq
to search for nil values in a list can evaluate functions of logical values of a list using variations of (memq nil my-list)
.
An example of a potential convenience function would be a boolean identity function that simply converts a value to its canonical boolean form.
(defun boolean-identity (x)
(if x t nil))
nil
or non-nil
). Processing how, to do what? Just what kind of values are in your "list of boolean values"?(if x t nil)
.(x)
would treatx
as a function and call it. I've only heard about purity in logic in the context of Prolog language, where there are logical and extra-/non- logical predicates. Is this what you mean when you say "purely logical functions"?