Auotolisp Subst-If / Subst-If-Not
These functions are derived from the Common Lisp Subst-If & Subst-If-Not functions. The Subst function is already implemented in AutoLisp, so no need to create a new one.
Code
(defun Subst-If (new predicate lst)
(if (= (type predicate) 'list) (setq predicate (eval predicate)))
(mapcar (function (lambda (item) (if (predicate item) new item))) lst))
(defun Subst-If-Not (new predicate lst)
(if (= (type predicate) 'list) (setq predicate (eval predicate)))
(mapcar (function (lambda (item) (if (predicate item) item new))) lst))
The Subst function could have been derived from such (though seeing as it's already implemented this would be unnecessary).
(defun Subst (new old lst)
(Subst-If new (function (lambda (item) (equal item old))) lst))
page revision: 3, last edited: 06 Apr 2012 11:58