comp.lang.ada
 help / color / mirror / Atom feed
* SET in Ada?
@ 2003-03-14 16:30 Alfred
  2003-03-14 16:45 ` Jeffrey Creem
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Alfred @ 2003-03-14 16:30 UTC (permalink / raw)


Hi I'm trying to convert some Modula code to Ada. There is a statement
like this:

IF i in {1,5,13,21}  THEN ...

How could this be translated to Ada, because as far as I know, Ada has
no similar "SET" handling.

--
----------------------------------------------
To send me email replace "SPAM" by "Jedermann"
----------------------------------------------



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

* Re: SET in Ada?
  2003-03-14 16:30 SET in Ada? Alfred
@ 2003-03-14 16:45 ` Jeffrey Creem
  2003-03-14 17:23 ` Robert A Duff
  2003-03-15  2:11 ` Jeffrey Carter
  2 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Creem @ 2003-03-14 16:45 UTC (permalink / raw)


If you need general purpse set operations then there are quite a few data
structure libraries out there you
can use.

if you are just trying to simulate the exact expression you wrote below then

case I is
  when 1 | 5 | 13 | 21 =>
    Do_The_Then_Stuff;
  when others =>
    Do_The_Else_Stuff;
end;

"Alfred" <SPAM@alfred-hilscher.de> wrote in message
news:3E7203B0.B5B7E076@alfred-hilscher.de...
> Hi I'm trying to convert some Modula code to Ada. There is a statement
> like this:
>
> IF i in {1,5,13,21}  THEN ...
>
> How could this be translated to Ada, because as far as I know, Ada has
> no similar "SET" handling.
>
> --
> ----------------------------------------------
> To send me email replace "SPAM" by "Jedermann"
> ----------------------------------------------





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

* Re: SET in Ada?
  2003-03-14 16:30 SET in Ada? Alfred
  2003-03-14 16:45 ` Jeffrey Creem
@ 2003-03-14 17:23 ` Robert A Duff
  2003-03-15  2:11 ` Jeffrey Carter
  2 siblings, 0 replies; 4+ messages in thread
From: Robert A Duff @ 2003-03-14 17:23 UTC (permalink / raw)


Alfred <SPAM@alfred-hilscher.de> writes:

> Hi I'm trying to convert some Modula code to Ada. There is a statement
> like this:
> 
> IF i in {1,5,13,21}  THEN ...
> 
> How could this be translated to Ada, because as far as I know, Ada has
> no similar "SET" handling.

The corresponding feature in Ada is a packed array of Booleans:

    type Bit_Set is array(...) of Boolean;
    pragma Pack(Bit_Set);
    Set: constant Bit_Set := (1 | 5 | 13 | 21 => True, others => False);
    if Set(I) then...

- Bob



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

* Re: SET in Ada?
  2003-03-14 16:30 SET in Ada? Alfred
  2003-03-14 16:45 ` Jeffrey Creem
  2003-03-14 17:23 ` Robert A Duff
@ 2003-03-15  2:11 ` Jeffrey Carter
  2 siblings, 0 replies; 4+ messages in thread
From: Jeffrey Carter @ 2003-03-15  2:11 UTC (permalink / raw)


Alfred wrote:
> Hi I'm trying to convert some Modula code to Ada. There is a statement
> like this:
> 
> IF i in {1,5,13,21}  THEN ...
> 
> How could this be translated to Ada, because as far as I know, Ada has
> no similar "SET" handling.

You could use PragmArc.Set_Discrete from the PragmAda Reusable Components

http://home.earthlink.net/~jrcarter010/pragmarc.htm

In which case your example would be written as

if Member (I, Make ((1, 5, 13, 21)) then

However, that's a poor use of sets. If you're not defining sets and 
checking for membership in a set variable you probably want a case 
statement.

-- 
Jeff Carter
"That was the most fun I've ever had without laughing."
Annie Hall




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

end of thread, other threads:[~2003-03-15  2:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-14 16:30 SET in Ada? Alfred
2003-03-14 16:45 ` Jeffrey Creem
2003-03-14 17:23 ` Robert A Duff
2003-03-15  2:11 ` Jeffrey Carter

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