[comp.lang.ada] Public domain set manipulation package

epstein@trwacs.UUCP (Jeremy Epstein) (05/29/90)

I'm sure there are at least a hundred of these out there, so...

I need a package that lets me declare a set of named items.
The ideal way would be a set of enumerated values.
I only need one operation on the set: examine whether a
particular element is in the set.

Since I have several such sets (of different enumerated types),
a generic seems to be appropriate.

I'm new to Ada, so any examples of how to use such a package
would also be appreciated.

Thanks!
--Jeremy

P.S. If it matters, I have VERDIX's VADS 5.7 compiler.
-- 
Jeremy Epstein
epstein%trwacs@uunet.uu.net
TRW Systems Division
703-876-8776

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (05/30/90)

In article <209@trwacs.UUCP>, epstein@trwacs.UUCP (Jeremy Epstein) writes:
> I need a package that lets me declare a set of named items.
> The ideal way would be a set of enumerated values.
> I only need one operation on the set: examine whether a
> particular element is in the set.

The Ada equivalent of Pascal's "set of EnumType" is
"array (EnumType) of BOOLEAN".  For example,
	type COLOR is (WHITE, RED, YELLOW, GREEN, BLUE, BROWN, BLACK);
		-- LRM 3.3.1
	type COLOR_SET is array(COLOR) of BOOLEAN;

	c: COLOR;
	s: COLOR_SET;
The Ada equivalent of a Pascal set expression "[...]" is an
array aggregate, LRM 4.3.2, e.g.

	s := COLOR_SET'(RED=>TRUE, GREEN=>TRUE, others=>FALSE);

The Ada equivalent of Pascal's "c IN s" is just "s(c)", e.g.
	if s(c) then -- the colour c is in the set of colours s

The boolean operators and, or, xor, not apply to one dimensional
boolean arrays (LRM 4.5.1, 4.5.6) and equality tests = /= work the
way you would expect (LRM 4.5.2).

So you see that full support for Pascal-like sets is already a
standard part of the Ada language.

-- 
"A 7th class of programs, correct in every way, is believed to exist by a
few computer scientists.  However, no example could be found to include here."