Re: (apply #'and '(t t nil)) not work



f> Apparently and is not a normal function like +, -, ...
f> I can write (and t t nil), but if the parameters are packaged into a
f> list, how can I do?

indeed, AND is not a function, it's a special operator, pretty close to IF
or WHEN -- it stops evaluating as soon as it get first NIL (this is called
short circuiting sometimes).
there is a function called EVERY, it does exactly what you need:

CL-USER> (every #'identity '(t t nil))
NIL
CL-USER> (every #'identity '(t t t))
T

of course you can define your own function -- to get rid of #'indetity
parameter, or allowing it to agruments directly. i.e.

(defun my-and (&rest args) (every #'identity args))

CL-USER> (my-and t t nil)
NIL
CL-USER> (apply #'my-and '(t t nil))
NIL

this looks just like AND, but it does not short-circuit evaluation.


.



Relevant Pages

  • Re: Noob question I think
    ... so I get and error that says nil is not of type NO. ... CL-USER> pai linha coluna id-nr) ... CL-USER> (defun insereMP (abertos no) ...
    (comp.lang.lisp)
  • Re: #0= ... #0#
    ... (do ((line (read-line stream nil nil) ... CL-USER> &body code) ... CL-USER> (write (macroexpand-1 form) ... The macro has built a confluent data structure. ...
    (comp.lang.lisp)
  • Re: How to eliminate eval?
    ... CL-USER> ) ... NIL)) ) ... CL-USER> (create-parameter 'a nil) ... (create-parameter (intern var) ...
    (comp.lang.lisp)
  • Re: (apply #and (t t nil)) not work
    ... CL-USER> (my-and t t nil) ... (defmacro andl (lst) ... variable QUOTE has no value ...
    (comp.lang.lisp)
  • Re: Macro woes
    ... CL-USER> (macroexpand '(test #'+)) ... CL-USER> `,(functionp x)) ... always expands into NIL. ...
    (comp.lang.lisp)