* 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