Emacs Lisp: Some and Every
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”.
Emacs Lisp Misc Essays
- Text Processing vs Structured
- Elisp coding style: let forms
- ELisp Naming Convention
- Some and Every
- What is the Function fn?
- Symbol vs String
- Meaning of Lisp List, Function Type, and Syntax Coloring
- Elisp vs Perl: Validate File Links
- Emacs Lisp: Relation of Curor Position to Begin/End of Matching Pairs in Source Code
- Text Processing: ELisp vs Perl
- Can ELisp Fix Its Namespace Problem by Copying JavaScript Practice?
- ELisp vs JavaScript
- Controversy of Common Lisp Package in ELisp
- Lisp List Problem
- Lisp-1 vs Lisp-2
- ELisp Problems: Trim String, Regex Match Data, Lacking Namespace
- Functional Programing: Function Output Should Always Have the Same Structure