Emacs Lisp: Some and Every

By Xah Lee. Date: . Last updated: .

Here's how to write “every” and “some” functions.

(defun my-some (@list)
  "return t if at least one element is true"
  (eval `(or ,@ @list)))

(defun my-every (@list)
  "return t if at least one element is true"
  (eval `(and ,@ @list)))

Here's another solution, using the cl library.

(require 'cl-extra)

;; return true if any element is true
(cl-some #'identity '(nil t ))

if you try to create a “some” function using cl-reduce with or, you get the same error “invalid-function or”

Here's naive try using apply.

(apply #'or '( nil nil t))

;; Debugger entered--Lisp error: (invalid-function or)
;;   or(nil nil t)
;;   apply(or (nil nil t))
;;   eval((apply (function or) (quote (nil nil t))) nil)
;;   elisp--eval-last-sexp(nil)
;;   eval-last-sexp(nil)
;;   funcall-interactively(eval-last-sexp nil)
;;   call-interactively(eval-last-sexp nil nil)
;;   command-execute(eval-last-sexp)

It doesn't work because “or” is a “special form”.

Like it? Buy Xah Emacs Tutorial. Thanks.