www.delorie.com/gnu/docs/guile/guile_451.html   search  
 
Buy GNU books!


Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

39.3.10 Set Operations on Lists

Lists can be used for representing sets of objects. The procedures documented in this section can be used for such set representations. Man combining several sets or adding elements, they make sure that no object is contained more than once in a given list. Please note that lists are not a too efficient implementation method for sets, so if you need high performance, you should think about implementing a custom data structure for representing sets, such as trees, bitsets, hash tables or something similar.

All these procedures accept an equality predicate as the first argument. This predicate is used for testing the objects in the list sets for sameness.

Scheme Procedure: lset<= = list1 ...
Return #t if every listi is a subset of listi+1, otherwise return #f. Returns #t if called with less than two arguments. = is used for testing element equality.

Scheme Procedure: lset= = list1 list2 ...
Return #t if all argument lists are equal. = is used for testing element equality.

Scheme Procedure: lset-adjoin = list elt1 ...
Scheme Procedure: lset-adjoin! = list elt1 ...
Add all elts to the list list, suppressing duplicates and return the resulting list. lset-adjoin! is allowed, but not required to modify its first argument. = is used for testing element equality.

Scheme Procedure: lset-union = list1 ...
Scheme Procedure: lset-union! = list1 ...
Return the union of all argument list sets. The union is the set of all elements which appear in any of the argument sets. lset-union! is allowed, but not required to modify its first argument. = is used for testing element equality.

Scheme Procedure: lset-intersection = list1 list2 ...
Scheme Procedure: lset-intersection! = list1 list2 ...
Return the intersection of all argument list sets. The intersection is the set containing all elements which appear in all argument sets. lset-intersection! is allowed, but not required to modify its first argument. = is used for testing element equality.

Scheme Procedure: lset-difference = list1 list2 ...
Scheme Procedure: lset-difference! = list1 list2 ...
Return the difference of all argument list sets. The difference is the the set containing all elements of the first list which do not appear in the other lists. lset-difference! is allowed, but not required to modify its first argument. = is used for testing element equality.

Scheme Procedure: lset-xor = list1 ...
Scheme Procedure: lset-xor! = list1 ...
Return the set containing all elements which appear in the first argument list set, but not in the second; or, more generally: which appear in an odd number of sets. lset-xor! is allowed, but not required to modify its first argument. = is used for testing element equality.

Scheme Procedure: lset-diff+intersection = list1 list2 ...
Scheme Procedure: lset-diff+intersection! = list1 list2 ...
Return two values, the difference and the intersection of the argument list sets. This works like a combination of lset-difference and lset-intersection, but is more efficient. lset-diff+intersection! is allowed, but not required to modify its first argument. = is used for testing element equality. You have to use some means to deal with the multiple values these procedures return (see section 26.6 Returning and Accepting Multiple Values).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003