[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Flying off the handle: one more time on SUBST



The last (second) try was buggy; here's a corrected version.
Note the use of &REST with &KEY, and the slick use of APPLY:

(defun subst (old new tree @rest x @key test test-not key)
  (cond ((atom tree)
	 (if (satisfies-the-test old tree :test test
				 :test-not test-not :key key)
	     new tree))
	(t (let ((a (apply #'subst old new (car tree) x))
		 (d (apply #'subst old new (cdr tree) x)))
	     (if (and (eq a (car tree)) (eq d (cdr tree)))
		 tree
		 (cons a d))))))

--Guy
-------