- delete x list #!optional =procedure
- delete! x list #!optional =procedure
delete uses the comparison procedure =, which defaults to equal?, to find all elements of LIST that are equal to X, and deletes them from LIST. The dynamic order in which the various applications of = are made is not specified.
The list is not disordered -- elements that appear in the result list occur in the same order as they occur in the argument list. The result may share a common tail with the argument list.
Note that fully general element deletion can be performed with the remove and remove! procedures, e.g.:
;; Delete all the even elements from LIS: (remove even? lis)
The comparison procedure is used in this way: (= X E_I). That is, X is always the first argument, and a list element is always the second argument. The comparison procedure will be used to compare each element of LIST exactly once; the order in which it is applied to the various E_I is not specified. Thus, one can reliably remove all the numbers greater than five from a list with (delete 5 list <)
delete! is the linear-update variant of delete. It is allowed, but not required, to alter the cons cells in its argument list to construct the result.