And / Or Macros for LISP

In case LISP programmers would like to implement && and || operators, the way they exist in C, the way to do that is as follows:

 


(defmacro && (head &rest tail)
    `(if ,head
        ,(if (null tail)
            T
            `(&& ,@tail) ) ) )

(defmacro || (head &rest tail)
    `(if ,head
        T
        ,(if (null tail)
            NIL
            `(|| ,@tail) ) ) )


 

Bear In Mind, within LISP, Not every successful function-call returns non-NIL. Therefore, I would use a slightly fancier approach, if any…

Continue reading And / Or Macros for LISP