Subversion Repositories programming

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
72 irasnyd 1
;Written By: Ira Snyder
2
;Due Date:   02-28-2005
3
;Homework #: HW12
4
 
5
;;; This is the generic implementation of the recursive schema OP-SOME.
6
;;; It takes 3 parameters:
7
;;;   CONDITION: when this is true, the operation happens on that element
8
;;;   OP: the operation to happen on the values that satisfy CONDITION
9
;;;   ARG: the list of items on which to operate
10
;;;
11
;;; Example: (OP-SOME #'oddp #'sq '(1 2 3 4 5)) -> (1 2 9 4 25)
12
(defun OP-SOME (CONDITION OP ARG)
13
  (cond
14
    ((null ARG)                    nil)
15
    ((funcall CONDITION (car ARG)) (cons (funcall OP (car ARG)) 
16
                                         (OP-SOME CONDITION OP (cdr ARG))))
17
    (t                             (cons (car ARG) 
18
                                         (OP-SOME CONDITION OP (cdr ARG))))
19
  )
20
)
21
 
22
;;; Returns the square of the number passed in as a parameter.
23
;;; This is to aid in testing of OP-SOME
24
(defun SQ (NUM)
25
  (* NUM NUM)
26
)
27