difference is a binary operation yielding the set A - B.
(define difference
(function metaset ((obj1 metaset)
(obj2 metaset))
; Check to see if both
; arguments are explicit.
(if (and (explicit? obj1) (explicit? obj2))
(letrec ((internal
; Define an internal recursive
; procedure.
(lambda (a b diff)
; A and B are lists containing
; the members of the input
; sets, and DIFF is a list
; containing the elements of A
; not in B. A should be no
; larger than B for optimal
; efficiency.
(if (equal? a '())
; Is A empty?
; We're done - return intersection.
(cons 'set diff)
; A not empty. Check to see if
; (car A) in B...
(if (member (car a) b)
; ...it is. Call internal
; with original DIFF list.
(internal (cdr a) b diff)
; Otherwise, call with
; updated DIFF list.
(internal (cdr a) b (cons (car a) diff)))))))
; We have defined internal.
; Now, apply it to the
; arguments (which we already
; know are both sets).
(internal (cdr obj1) (cdr obj2) '()))
`(difference ,obj1 ,obj2))))