comp.lang.ada
 help / color / mirror / Atom feed
* Public domain set manipulation package
@ 1990-05-29 13:31 Jeremy Epstein
  1990-05-30  9:38 ` Richard A. O'Keefe
  0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Epstein @ 1990-05-29 13:31 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Public domain set manipulation package
  1990-05-29 13:31 Public domain set manipulation package Jeremy Epstein
@ 1990-05-30  9:38 ` Richard A. O'Keefe
  0 siblings, 0 replies; 2+ messages in thread
From: Richard A. O'Keefe @ 1990-05-30  9:38 UTC (permalink / raw)


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."

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1990-05-30  9:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1990-05-29 13:31 Public domain set manipulation package Jeremy Epstein
1990-05-30  9:38 ` Richard A. O'Keefe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox