0

I'm trying to apply a logic function over a list, but:

e.g.(apply 'and some_list) give me Invalid function: and.

There is a way to apply a logical function to a list?

Drew
  • 75,699
  • 9
  • 109
  • 225
Francesco Cadei
  • 327
  • 3
  • 17

1 Answers1

3

This is because and is not a function (it is a special form).

Note that C-h f and tells you "and is a special form in `C source code'."

apply must be used with a function.

The manual says:

‘apply’ returns the result of calling FUNCTION.  As with ‘funcall’,
 FUNCTION must either be a Lisp function or a primitive function;
 special forms and macros do not make sense in ‘apply’.
phils
  • 48,657
  • 3
  • 76
  • 115
  • there is any `and` function in elisp? – Francesco Cadei Oct 15 '18 at 21:47
  • 1
    It's not possible to write `and` as a function -- functions evaluate *all* of their arguments, whereas macros and special forms receive their arguments un-evaluated (which is necessary for `and`, which must not evaluate the remaining arguments if it has already failed). – phils Oct 15 '18 at 21:52
  • there is a non lazy set of logic functions? or, what is the best way to do this? – Francesco Cadei Oct 15 '18 at 21:55
  • 4
    @FrancescoCadei For `and` you have `(cl-every #'identity some_list)` and for `or` you have `(cl-some #'identity some_list)`. – Tobias Oct 15 '18 at 21:59
  • 4
    If all you want is a nil or non-nil result, then `(memq nil LIST)` will tell you if any of the list elements is `nil`. – phils Oct 15 '18 at 21:59