next up previous contents index
Next: Associative Lists in A++ Up: Set Operations Previous: Adding an element to   Contents   Index


Combining two sets: `union'

This abstraction takes two lists as arguments and creates a new list having the property of a set by ensuring that elements may not occur more than once in the resulting list.


\begin{lstlisting}[language=Scm]{}
(define union (lambda(s1 s2)
(if (nullp s1) ...
...
(union (cdr s1) s2)
(cons (car s1) (union (cdr s1) s2))))))
\end{lstlisting}


\begin{lstlisting}[language=Scm]{}
(define l1 (cons one
(cons two
(cons thre...
...! (union l1 l2))
--> 1
2
3
4 ;; kommt nur einmal vor
5
6
\end{lstlisting}



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