comp.lang.ada
 help / color / mirror / Atom feed
* Sets in Ada
@ 1988-12-03 22:36 Erland Sommarskog
  0 siblings, 0 replies; only message in thread
From: Erland Sommarskog @ 1988-12-03 22:36 UTC (permalink / raw)


Ray Trent (trent@unix.sri.com) writes:
>Another change I'd like to see. (upward compatible this time) Allow:
>
>  if A in B | C | D | Q | Y | N then
>    ...
>  end if;
>
>I.e. an extension of the membership idea. It's ridiculous to me that

Although it would be nice to have in the language as such, it is fairly 
easy to write your own generic Set package. I include some excerpts from 
my own:

   Generic
      Type Element is (<>);
   Package Set_handler is
   
   Type Set_type is private;
   Empty_set : Constant Set_type;
   Type Element_array is array(integer range <>) of Element;

   Function Set(Elem : Element) return Set_type;   
   Function Set(Elems : Element_array) return Set_type;
   -- A set of all compontens in Elems.
   Function Set(From, To : Element) return Set_type; 
   -- A set of the range From..To.
...
   Function In_set(Elem : Element; A : Set_type) return boolean; 
   
Instantiate that on your favourite enumarate and you can write:

     IF In_set(A, Set((B, C, D, Y, Z))) THEN 
     
Somewhat obscure, agreed. (It would have been nice here if the IN
operator had been overloadable.)
-- 
Erland Sommarskog
ENEA Data, Stockholm
sommar@enea.se
"Frequently, unexpected errors are entirely unpredictable" - Digital Equipment

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1988-12-03 22:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1988-12-03 22:36 Sets in Ada Erland Sommarskog

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