[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Proposed definition of SUBST
- To: common-lisp at SU-AI
- Subject: Proposed definition of SUBST
- From: STEELE at CMU-20C
- Date: Sat, 04 Sep 1982 04:25:00 -0000
Here is a tentative definition of SUBST for inclusion in the white pages:
(defun subst (old new tree @key (test #'eql testp)
(test-not nil test-not-p)
(key #'(lambda (x) x)))
(cond (test-not-p
(if testp @r[<signal-an-error>]
(subst old new tree
:test #'(lambda (x y) (not (funcall test-not x y)))
:key key)))
((atom tree)
(if (funcall test old tree) new tree))
(t (let ((a (subst old new (car tree) :test test :key key))
(d (subst old new (cdr tree) :test test :key key)))
(if (and (eq a (car tree)) (eq d (cdr tree)))
tree
(cons a d))))))
I had two problems. One is that :TEST-NOT is a pain to implement.
Either I have to use the subterfuge I did here, which is clumsy or slow,
or else I have to implement SUBST twice, once for the version that
uses TEST and once for the one that uses TEST-NOT. Actually, what
I need is a function XOR, taking two boolean values (NIL/not-NIL)
and returning their xor, so that I can pass a TEST-NOT-P flag and
xor it with the result of the predicate.
The other problem is that I wish there were a standard identity function
for use in initializing the :KEY parameter. (I refuse to use VALUES!)
Any suggestions on this or other aspects of the above definition?
--Guy
-------