Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

subst

subst

type: function (subr) 
location: built-in
source file: xllist.c
Common LISP compatible: similar
supported on: all machines

SYNTAX

(subst <new-expr>   [ { :test | :test-not }  ] )
        <old-expr>      -       the expression to search for 
        <new-expr>      -       the expression to replace <old-expr> with
        <expr>          -       the expression to substitute within - atom/list
        <test>          -       optional test function (default is EQL)

DESCRIPTION

SUBST 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 which to perform.

EXAMPLES

(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 TRUE
(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 COMPATIBILITY: 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.


Go to the first, previous, next, last section, table of contents.