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


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'.


(define memberp 
   (lambda(x s)
      (if (nullp s)
         false
         (if (equaln x (car s)
            true
            (memberp x (cdr s)))))))


(define l1 (cons one (cons two (cons three 
                                        (cons four 
                                               nil)))))
;
(bdisp! (memberp three l1))
                             --> true
;
(bdisp! (memberp five l1))
                             --> false



Georg P. Loczewski 2004-03-05


Impressum und Datenschutz