;;;  File: Sums.lsp
;;; 
;;;  Demonstrate Helper Functions
;;; 
;;;  Author:  Bary W Pollack
;;;  Date:    Jan. 27, 2003
;;; 
;;;  sumN adds the elements of two lists, return a list result
;;;  The input lists must be the same length

;;;  --------------------------------------------------------------
;;;  sum1 is the simple, recursive definition

(defun sum1 (a b) (cond
    ((null a) b)
    ((null b) a)
    (t (cons (+ (car a) (car b)) (sum1 (cdr a) (cdr b)))) ))

;;;  --------------------------------------------------------------
;;;  sum2 uses a "Helper Function" to simplify the computation

(defun sum2 (a b) (sum3 a b nil))

(defun sum3 (a b r) (cond
    ((null a) r)
    (t (sum3 (cdr a) (cdr b) (cons (+ (car a) (car b)) r))) ))
