next up previous contents index
Next: Retrieving the n-th element Up: Basic utility abstractions for Previous: Determining the length of   Contents   Index


Removing an element from a list: `remove'

This abstraction creates a new list from the given list making sure that the element specified as first argument does not appear in the resulting list returned.


\begin{lstlisting}[language=Scm]{}
(define remove
(lambda(obj l)
(if (nullp l)...
...
(remove obj (cdr l))
(cons (car l) (remove obj (cdr l)))))))
\end{lstlisting}

\begin{lstlisting}[language=Scm]{}
(define l1 (cons one (cons two (cons three (c...
...four nil)))))
;
(ldisp! (remove three l1))
--> 1
--> 2
--> 4
\end{lstlisting}


domain access counter Georg P. Loczewski 2004-03-05