The in? predicate is a binary operator which tests an entity for membership in a set.
(define (in? obj class)
; First, check to see of OBJ
; is an instance (in the sense
; of a Java class instance) of
; CLASS.
(if (classType? class)
(isInstance? class obj)
; Check against
; core classes. This
; is essentially a re-write of
; core? with
; additional tests.
(case class
; Test against the container sets.
((sol) #t)
; Everything is a member of SOL.
((fundamental)
(fundamental? obj))
((core)
(core? obj))
((explicit)
(explicit? obj))
((derived)
(derived? obj))
; Test against the number sets.
((number)
(number? obj))
((complex)
(complex? obj))
((real)
(real? obj))
((rational)
(rational? obj))
((integer)
(integer? obj))
; Test against Sstring, Symbol,
; and Character.
((sstring)
(string? obj))
((symbol)
(symbol? obj))
((char)
(char? obj))
; Test against SSET, SORDERED,
; and UNORDERED.
((sset)
(set? obj))
((sordered)
(ordered? obj))
((unordered)
(and (set? obj) (not (ordered? obj))))
; Test against PAIR and LIST
; NOTE - in Sol, sets are not
; lists. However, when
; embedded in scheme they must
; be represented that way.
; Therefor, the scheme list?
; and pair? operators are not
; accurate when applied to a
; Sol set because they will
; return true.
((pair)
(and (pair? obj) (not (set? obj))))
((slist)
(and (list? obj) (not (set? obj))))
; Test against procedure.
; NOTE: this is not entirely
; accurate, as this test will
; inaccurately clasify Sol
; categories as procedures.
((procedure)
(procedure? obj))
; Test to see if object is #t
; or #f.
((boolean)
(or (eq? obj #t) (eq? obj #f)))
; At this point, we know that
; CLASS is not a core
; set, so check to see if it
; is an explicit or derived set.
(else
(cond
((explicit? class)
; It is. Check for membership.
(member obj (cdr class)))
((derived? class)
(let ((operation (car class))
(operands (cdr class))
(operand1 (cadr class))
(operand2 (caddr class)))
(cond
; If the operation is union...
((eq? operation 'union)
(or (in? obj operand1) (in? obj operand2)))
; Intersection...
((eq? operation 'intersection)
(and (in? obj operand1) (in? obj operand2)))
; Difference.
((eq? operation 'difference)
(and (in? obj operand1) (not (in? obj operand2))))
; The cartesian product
; operator is different - it
; may have two or more
; arguments. We need to
; define a recursive procedure
; for checking each element of
; the list against each
; argument of CROSS.
((eq? operation 'cross)
(letrec
((recursive-check
(lambda (a b)
(or (and (null? a) (null? b))
(and (not (or (null? a) (null? b)))
(in? (car a) (car b))
(recursive-check (cdr a) (cdr b)))))))
(and (list? obj) (recursive-check obj operands))))
(else (error "subset?: Bad derived set:" class)))))
; CLASS is not a Sol
; set. Return false, since obj
; can't possibly be a member.
(else #f))))))