(cons (copy-tree (car tree))
(copy-tree (cdr tree)))
tree))
+
+(defun subst (new old tree &key (key #'identity) (test #'eql))
+ (if (funcall test (funcall key tree) (funcall key old))
+ new
+ (if (consp tree)
+ (cons (subst new old (car tree) :key key :test test)
+ (subst new old (cdr tree) :key key :test test))
+ tree)))
prin1-to-string print proclaim prog1 prog2 progn psetq push
quote read-from-string remove remove-if remove-if-not return
return-from revappend reverse rplaca rplacd second set setf
- setq some string string-upcase string= stringp subseq
+ setq some string string-upcase string= stringp subseq subst
symbol-function symbol-name symbol-package symbol-plist
symbol-value symbolp t tagbody third throw truncate unless
unwind-protect values values-list variable warn when write-line
; Tests for list functions
+; COPY-TREE
(test (let* ((foo '((1 2) (3 4)))
(bar (copy-tree foo)))
;; (SETF (CAR (CAR FOO)) 0) doesn't work in the test for some reason,
;; Once it does the lists can be compared directly
(not (= (car (car foo))
(car (car bar))))))
+
+; SUBST
+; Can't really test this until EQUAL works properly on lists