comp.lang.ada
 help / color / mirror / Atom feed
From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe)
Subject: Re: Public domain set manipulation package
Date: 30 May 90 09:38:06 GMT	[thread overview]
Message-ID: <3108@goanna.cs.rmit.oz.au> (raw)
In-Reply-To: 209@trwacs.UUCP

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

      reply	other threads:[~1990-05-30  9:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-05-29 13:31 Public domain set manipulation package Jeremy Epstein
1990-05-30  9:38 ` Richard A. O'Keefe [this message]
replies disabled

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