Subversion Repositories programming

Rev

Rev 72 | Blame | Compare with Previous | Last modification | View Log | RSS feed

irasnyd@duallie lisp $ cat hw12.lisp
;Written By: Ira Snyder
;Due Date:   02-28-2005
;Homework #: HW12

;;; 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)
)

irasnyd@duallie lisp $ clisp -q

[1]> (load 'hw12.lisp)
;; Loading file hw12.lisp ...
;; Loaded file hw12.lisp
T
[2]> (OP-SOME #'oddp #'SQ nil)
NIL
[3]> (OP-SOME #'oddp #'SQ '(2))
(2)
[4]> (OP-SOME #'oddp #'SQ '(3))
(9)
[5]> (OP-SOME #'oddp #'SQ '(3 6 4 5 2))
(9 6 4 25 2)
[6]> (bye)
irasnyd@duallie lisp $