Next: Lists as Sets, Previous: List Functions, Up: Lists

These functions substitute elements throughout a tree of cons
cells. (See Sequence Functions, for the `cl-substitute`

function, which works on just the top-level elements of a list.)

— Function: **cl-subst**` new old tree ``&key :test :test-not :key`

This function substitutes occurrences of

oldwithnewintree, a tree of cons cells. It returns a substituted tree, which will be a copy except that it may share storage with the argumenttreein parts where no substitutions occurred. The originaltreeis not modified. This function recurses on, and compares againstold, both cars and cdrs of the component cons cells. Ifoldis itself a cons cell, then matching cells in the tree are substituted as usual without recursively substituting in that cell. Comparisons witholdare done according to the specified test (`eql`

by default). The`:key`

function is applied to the elements of the tree but not toold.

— Function: **cl-nsubst**` new old tree ``&key :test :test-not :key`

This function is like

`cl-subst`

, except that it works by destructive modification (by`setcar`

or`setcdr`

) rather than copying.

The `cl-subst-if`

, `cl-subst-if-not`

, `cl-nsubst-if`

, and
`cl-nsubst-if-not`

functions are defined similarly.

— Function: **cl-sublis**` alist tree ``&key :test :test-not :key`

This function is like

`cl-subst`

, except that it takes an association listalistofold-newpairs. Each element of the tree (after applying the`:key`

function, if any), is compared with the cars ofalist; if it matches, it is replaced by the corresponding cdr.