Subversion Repositories programming

Rev

Rev 100 | Details | Compare with Previous | 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
108 ira 4
;License: Public Domain
72 irasnyd 5
 
6
;;; This is the generic implementation of the recursive schema OP-SOME.
7
;;; It takes 3 parameters:
8
;;;   CONDITION: when this is true, the operation happens on that element
9
;;;   OP: the operation to happen on the values that satisfy CONDITION
10
;;;   ARG: the list of items on which to operate
11
;;;
12
;;; Example: (OP-SOME #'oddp #'sq '(1 2 3 4 5)) -> (1 2 9 4 25)
13
(defun OP-SOME (CONDITION OP ARG)
14
  (cond
15
    ((null ARG)                    nil)
16
    ((funcall CONDITION (car ARG)) (cons (funcall OP (car ARG)) 
17
                                         (OP-SOME CONDITION OP (cdr ARG))))
18
    (t                             (cons (car ARG) 
19
                                         (OP-SOME CONDITION OP (cdr ARG))))
20
  )
21
)
22
 
23
;;; Returns the square of the number passed in as a parameter.
24
;;; This is to aid in testing of OP-SOME
25
(defun SQ (NUM)
26
  (* NUM NUM)
27
)
28