next up previous contents index
Next: Combining two sets: `union' Up: Set Operations Previous: Checking for a member   Contents   Index


Adding an element to a set: `addelt'

This abstraction adds an element to a list if the element is not yet contained in the list thus preserving the essential characteristic of sets.


\begin{lstlisting}[language=Scm]{}
(define addelt (lambda(x s)
(if (memberp x s)
s
(cons x s))))
\end{lstlisting}



\begin{lstlisting}[language=Scm]{}
(define l1 (cons one (cons two (cons three
...
...l1)) ;; effective because not yet a member
--> 5
1
2
3
4
;
\end{lstlisting}



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