Searches a list for an old item and returns a copy of the list with a new item substituted in place of every occurrence of the old item
(subst newitem olditem lst)
Arguments
An atom or list.
An atom or list.
A list.
Return Values
subst returns lst unchanged.
A list, with newitem replacing all occurrences of olditem. If olditem is not found in lst,Examples
Command: (setq sample '(a b (c d) b))
(A B (C D) B)
Command: (subst 'qq 'b sample)
(A QQ (C D) QQ)
Command: (subst 'qq 'z sample)
(A B (C D) B)
Command: (subst 'qq '(c d) sample)
(A B QQ B)
Command: (subst '(qq rr) '(c d) sample)
(A B (QQ RR) B)
Command: (subst '(qq rr) 'z sample)
(A B (C D) B)
assoc, subst provides a convenient means of replacing the value associated with one key in an association list, as demonstrated by the following function calls.
When used in conjunction withwho to an association list:
Set variableCommand: (setq who '((first john) (mid q) (last public)))
((FIRST JOHN) (MID Q) (LAST PUBLIC))
old to (FIRST JOHN) and new to (FIRST J):
The following setsCommand: (setq old (assoc 'first who) new '(first j))
(FIRST J)
Finally, replace the value of the first item in the association list:
Command: (subst new old who)
((FIRST J) (MID Q) (LAST PUBLIC))