The 'subst' function searches through an 'expr' and replaces each of the 'old-expr' elements with the 'new-expr'. The 'expr' with the substitutions, if any, is returned. You may specify your own test with the ':test' and ':test-not' keywords followed by the 'test' you wish to perform.
(subst 'new 'old '(old mid dif)) ; returns (NEW MID DIF) (subst '(a) 'old '(old mid dif)) ; returns ((A) MID DIF) (subst "a" 'old '(old mid dif)) ; returns ("a" MID DIF) (defun mytest (x y) (princ x) (princ " ") ; define a test function (princ y) (terpri) ; that prints the arguments T ) ; and always returns T (subst 'a 'b '(a b c d) :test 'mytest) ; prints (A B C D) B returns A (subst 'a 'b '(a b) :test-not 'mytest) ; prints (A B) B ; A B ; (B) B ; B B ; NIL B returns (A B)
Note: The 'subst' function can work with a list or string as the 'expr' However, the default eql test does not work with lists or strings, only symbols and numbers. To make this work, you need to use the ':test' keyword along with equal for 'test'.
Common Lisp: Common Lisp supports the use of the ':key' keyword which specifies a function that is applied to each element of 'expr' before it is tested. XLISP does not support this.
See the
subst
function in the