Rev 64 | Blame | Compare with Previous | Last modification | View Log | RSS feed
irasnyd@duallie lisp $ cat hw04.lisp
;;;
;;; A recursive function which takes two lists of integers and returns
;;; a list of integers in which each element is the sun of the
;;; corresponding elements of the incoming lists. The lists are
;;; not required to be the same length.
;;;
;;; Examples:
;;; (AL1 '(3 1 4) '(8 2 5)) --> (11 3 9)
;;; (AL1 '(3 1 4) '(2 2)) --> (5 3 4)
;;; (AL1 '(3 1 4) nil) --> (3 1 4)
;;;
(defun AL1 (L1 L2)
(cond
((null L1) L2)
((null L2) L1)
(t (cons (+ (car L1) (car L2)) (AL1 (cdr L1) (cdr L2))))
)
)
irasnyd@duallie lisp $ clisp -q
[1]> (load 'hw04.lisp)
;; Loading file hw04.lisp ...
;; Loaded file hw04.lisp
T
[2]> (AL1 '(3 1 4) '(8 2 5))
(11 3 9)
[3]> (AL1 '(3 1 4) '(2 2))
(5 3 4)
[4]> (AL1 '(3 1 4) nil)
(3 1 4)
[5]> (AL1 nil nil)
NIL
[6]> (AL1 '(2 2) '(3 1 4))
(5 3 4)
[7]> (bye)
irasnyd@duallie lisp $