;; This program is a flexible, functionally designed program ;; that finds all of the objects that satisfy a given ;; test (given as parameter OBJ-TEST, a function binding) ;; and returns a list of them according to OBJ-ORDER ;; (another parameter that is also a function binding) (defun mycollect (l obj-test obj-order) (cond ((null l) nil) ((atom l) (and (funcall obj-test l) (list l))) (t (sort (nconc (mycollect (car l) obj-test obj-order) (mycollect (cdr l) obj-test obj-order)) obj-order)))) (defun mycollect-all (l) "Uses mycollect to return all objects in l in order -- basically just FLATTEN-LIST" (mycollect l #'(lambda(x) t) #'(lambda(x y) nil))) (defun mycollect-posint (l) "Uses mycollect to return all positive integers -- just like POSINT" (mycollect l #'(lambda(x) (and (integerp x) (> x 0))) #'(lambda(x y) nil))) (defun mycollect-posint-sorted (l) "Uses mycollect to return all positive integers in sorted order" (mycollect l #'(lambda(x) (and (integerp x) (> x 0))) #'(lambda(x y) (< x y)))) (defun mycollect-posint-reverse (l) "Uses mycollect to return all positive integers in reverse sorted order" (mycollect l #'(lambda(x) (and (integerp x) (> x 0))) #'>))