LISP Sum of list function

USING IF

(defun sum(list)
      (if (null list) 0 (+ (car list) (sum(cdr list))) )
)

USING COND

(defun sum(list)
      (cond ( (null list) 0 )
                ( (+ (car list) (sum(cdr list))) )
      )
)

USING COND AND ELSE

(defun sum(list)
      (cond ( (null list) 0 )
                (else (+ (car list) (sum(cdr list))) )
      )
)

Comments