next up previous contents index
Next: Adding an element to Up: Set Operations Previous: Set Operations   Contents   Index


Checking for a member in a set: `memberp'

This abstraction is applicable for lists in general and also for sets specifically checking, whether a certain element is contained in the list or set.

The difference between the abstraction `locate' and `memberp' consists in the first argument being a condition for `memberp' and not a predicate function.

`memberp' appears in this category because it is used by the abstraction `create a union of two sets'.


\begin{lstlisting}[language=Scm]{}
(define memberp (lambda(x s)
(if (nullp s)
false
(if (equaln x (car s)
true
(memberp x (cdr s)))))))
\end{lstlisting}

\begin{lstlisting}[language=Scm]{}
(define l1 (cons one (cons two (cons three
...
...rp three l1))
--> true
;
(bdisp! (memberp five l1))
--> false
\end{lstlisting}



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