This section describes the (rnrs enums (6))
library for dealing with
enumerated values and sets of enumerated values. Enumerated values are represented
by ordinary symbols, while finite sets of enumerated values form a separate type,
known as the enumeration sets. The enumeration sets are further partitioned
into sets that share the same universe and enumeration type. These
universes and enumeration types are created by the make-enumeration
procedure. Each call to that procedure creates a new enumeration type.
[R6RS] This library interprets each enumeration set with respect to its specific universe of symbols and enumeration type. This facilitates efficient implementation of enumeration sets and enables the complement operation.
In the descriptions of the following procedures, enum-set ranges over the enumeration sets, which are defined as the subsets of the universes that can be defined using make-enumeration.
[R6RS] Symbol-list must be a list of symbols.
The make-enumeration
procedure creates a new enumeration type whose
universe consists of those symbols (in canonical order of their first appearance
in the list) and returns that universe as an enumeration set whose universe is
itself and whose enumeration type is the newly created enumeration type.
[R6RS] Returns the set of all symbols that comprise the universe of its argument, as an enumeration set.
[R6RS] Returns a unary procedure that, given a symbol that is in the universe of enum-set, returns its 0-origin index within the canonical ordering of the symbols in the universe; given a value not in the universe, the unary procedure returns #f.
[R6RS] Returns a unary procedure that, given a list of symbols that belong to the universe of enum-set, returns a subset of that universe that contains exactly the symbols in the list. The values in the list must all belong to the universe.
[R6RS] Returns a list of the symbols that belong to its argument, in the canonical order of the universe of enum-set.
[R6RS] The enum-set-member?
procedure returns #t if its first
argument is an element of its second argument, #f otherwise.
The enum-set-subset?
procedure returns #t if the universe of
enum-set1 is a subset of the universe of enum-set2 (considered as
sets of symbols) and every element of enum-set1 is a member of
enum-set2. It returns #f otherwise.
The enum-set=?
procedure returns #t if enum-set1 is a subset of
enum-set2 and vice versa, as determined by the enum-set-subset?
procedure. This implies that the universes of the two sets are equal as sets of
symbols, but does not imply that they are equal as enumeration types. Otherwise,
#f is returned.
[R6RS] Enum-set1 and enum-set2 must be enumeration sets that have the same enumeration type.
The enum-set-union
procedure returns the union of enum-set1 and
enum-set2.
The enum-set-intersection
procedure returns the intersection of
enum-set1 and enum-set2.
The enum-set-difference
procedure returns the difference of _enum-set1_and enum-set2.
[R6RS] Returns enum-set's complement with respect to its universe.
[R6RS] Projects enum-set1 into the universe of enum-set2, dropping any elements of enum-set1 that do not belong to the universe of enum-set2. (If enum-set1 is a subset of the universe of its second, no elements are dropped, and the injection is returned.)
[R6RS] The define-enumeration
form defines an enumeration type and
provides two macros for constructing its members and sets of its members.
A define-enumeration
form is a definition and can appear anywhere any
other definition can appear.
Type-name is an identifier that is bound as a syntactic keyword; symbol ... are the symbols that comprise the universe of the enumeration (in order).
(_type-name_ _symbol_)
checks at macro-expansion time whether the
name of symbol is in the universe associated with type-name. If it is,
(_type-name_ _symbol_)
is equivalent to symbol. It is a syntax
violation if it is not.
Constructor-syntax is an identifier that is bound to a macro that, given any finite sequence of the symbols in the universe, possibly with duplicates, expands into an expression that evaluates to the enumeration set of those symbols.
(_constructor-syntax_ _symbol ..._)
checks at macro-expansion
time whether every symbol ... is in the universe associated with
type-name. It is a syntax violation if one or more is not. Otherwise
(_constructor-syntax_ _symbol ..._)
is equivalent to
((enum-set-constructor (_constructor-syntax_))
'(_symbol ..._))
.