Subversion Repositories programming

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
64 irasnyd 1
irasnyd@duallie lisp $ cat hw04.lisp
2
;;;
3
;;; A recursive function which takes two lists of integers and returns
4
;;; a list of integers in which each element is the sun of the
5
;;; corresponding elements of the incoming lists. The lists are
6
;;; not required to be the same length.
7
;;;
8
;;; Examples:
9
;;; (AL1 '(3 1 4) '(8 2 5)) --> (11 3 9)
10
;;; (AL1 '(3 1 4) '(2 2)) --> (5 3 4)
11
;;; (AL1 '(3 1 4) nil) --> (3 1 4)
12
;;;
13
(defun AL1 (L1 L2)
14
  (cond
15
    ((null L1) L2)
16
    ((null L2) L1)
17
    (t         (cons (+ (car L1) (car L2)) (AL1 (cdr L1) (cdr L2))))
18
  )
19
)
20
 
21
irasnyd@duallie lisp $ clisp -q
22
 
23
[1]> (load 'hw04.lisp)
24
;; Loading file hw04.lisp ...
25
;; Loaded file hw04.lisp
26
T
27
[2]> (AL1 '(3 1 4) '(8 2 5))
28
(11 3 9)
29
[3]> (AL1 '(3 1 4) '(2 2))
30
(5 3 4)
31
[4]> (AL1 '(3 1 4) nil)
32
(3 1 4)
33
[5]> (AL1 nil nil)
34
NIL
35
[6]> (AL1 '(2 2) '(3 1 4))
36
(5 3 4)
37
[7]> (bye)
38
irasnyd@duallie lisp $