Rev 100 | Blame | Compare with Previous | Last modification | View Log | RSS feed
;Written By: Ira Snyder
;Due Date: 02-28-2005
;Homework #: HW12
;License: Public Domain
;;; This is the generic implementation of the recursive schema OP-SOME.
;;; It takes 3 parameters:
;;; CONDITION: when this is true, the operation happens on that element
;;; OP: the operation to happen on the values that satisfy CONDITION
;;; ARG: the list of items on which to operate
;;;
;;; Example: (OP-SOME #'oddp #'sq '(1 2 3 4 5)) -> (1 2 9 4 25)
(defun OP-SOME (CONDITION OP ARG)
(cond
((null ARG) nil)
((funcall CONDITION (car ARG)) (cons (funcall OP (car ARG))
(OP-SOME CONDITION OP (cdr ARG))))
(t (cons (car ARG)
(OP-SOME CONDITION OP (cdr ARG))))
)
)
;;; Returns the square of the number passed in as a parameter.
;;; This is to aid in testing of OP-SOME
(defun SQ (NUM)
(* NUM NUM)
)