Next: , Up: Libraries


6.1 Boxed bitwise-integer masks

Scheme48 provides a facility for generalized boxed bitwise-integer masks. Masks represent sets of elements. An element is any arbitrary object that represents an index into a bit mask; mask types are parameterized by an isomorphism between elements and their integer indices. Usual abstract set operations are available on masks. The mask facility is divided into two parts: the mask-types structure, which provides the operations on the generalized mask type descriptors; and the masks structure, for the operations on masks themselves.

6.1.1 Mask types

— procedure: make-mask-type name elt? index->elt elt->index size –> mask-type
— procedure: mask-type? object –> boolean
— procedure: mask? object –> boolean

Make-mask-type constructs a mask type with the given name. Elements of this mask type must satisfy the predicate elt?. Integer->elt is a unary procedure that maps bit mask indices to possible set elements; elt->integer maps possible set elements to bit mask indices. Size is the number of possible elements of masks of the new type, i.e. the number of bits needed to represent the internal bit mask. Mask? is the disjoint type predicate for mask objects.

— procedure: mask-type mask –> mask-type
— procedure: mask-has-type? mask type –> boolean

Mask-type returns mask's type. Mask-has-type? returns #t if mask's type is the mask type type or #f if not.

The mask-types structure, not the masks structure, exports mask? and mask-has-type?: it is expected that programmers who implement mask types will define type predicates for masks of their type based on mask? and mask-has-type?, along with constructors &c. for their masks.

— procedure: integer->mask type integer –> mask
— procedure: list->mask type elts –> mask

Integer->mask returns a mask of type type that contains all the possible elements e of the type type such that the bit at e's index is set. List->mask returns a mask whose type is type containing all of the elements in the list elts.

6.1.2 Masks

— procedure: mask->integer mask –> integer
— procedure: mask->list mask –> element-list

Mask->integer returns the integer bit set that mask uses to represent the element set. Mask->list returns a list of all the elements that mask contains.

— procedure: mask-member? mask elt –> boolean
— procedure: mask-set mask elt ... –> mask
— procedure: mask-clear mask elt ... –> mask

Mask-member? returns true if elt is a member of the mask mask, or #f if not. Mask-set returns a mask with all the elements in mask as well as each elt .... Mask-clear returns a mask with all the elements in mask but with none of elt ....

— procedure: mask-union mask1 mask2 ... –> mask
— procedure: mask-intersection mask1 mask2 ... –> mask
— procedure: mask-subtract maska maskb –> mask
— procedure: mask-negate mask –> mask

Set operations on masks. Mask-union returns a mask containing every element that is a member of any one of its arguments. Mask-intersection returns a mask containing every element that is a member of every one of its arguments. Mask-subtract returns a mask of every element that is in maska but not also in maskb. Mask-negate returns a mask whose members are every possible element of mask's type that is not in mask.