comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst@cts.com>
Subject: Re: if X in 1..35000 versus Boolean
Date: 16 Jul 2002 01:18:54 -0700
Date: 2002-07-16T01:18:54-07:00	[thread overview]
Message-ID: <yecfzykccgh.fsf@king.cts.com> (raw)
In-Reply-To: pan.2002.07.13.19.33.33.634009.1168@gmx.net

Jan Prazak <janp9@gmx.net> writes:
> On Sat, 13 Jul 2002 15:27:03 -0100, Frank J. Lhota wrote:
> > Also, 1 .. 35000 is an integer range, not an enumeration type.
> 
> But the word "in" tests, if given object (variable...) is
> in given enumeration type.
> 
> type num : (1, 2, 3, 4);
> 
> if 3 in num then ...
> 
> -- this should be the same as: if 3 in (1,2,3,4);
> -- and also the same as: if 3 in 1..4;
> 
> So I assume that "if X in 1..35000" has the same rules.

I think you're thinking of Pascal sets, not enumeration types.  Ada
doesn't have built-in set types, though they're easy enough to
implement.

If I recall correctly (it's been a while), in Pascal you can write
something like:

    if X in [1 .. 4] then (* This is Pascal, not Ada *)
    begin
        ...;
    end;

where [1 .. 4] is a set value constructor.  A naive Pascal compiler
would build a set value with bits 1, 2, 3, and 4 set, and all other
bits cleared, and test whether bit X is set.  A more clever Pascal
compiler might generate code equivalent to X >= 1 and X <= 4.

You can also do more complex things like

    if X in [1 .. 4, 7 .. 9, 12] then (* This is Pascal, not Ada *)
    begin
        ...;
    end;

The Ada construct 1 .. 4 is *not* a set value constructor, it's a
range.  Given the condition "X in 1 .. 4", there's no reason for the
compiler to generate anything more complicated than "X >= 1 and X <= 4".
There is no direct Ada equivalent to "X in [1..4, 7..9, 12]".

An enumeration type is something else; for example:
    type Color is (Red, Blue, Green);
Note that the values are identifiers, not numeric literals.

I suggest you find a good Ada textbook or online tutorial.

-- 
Keith Thompson (The_Other_Keith) kst@cts.com  <http://www.ghoti.net/~kst>
San Diego Supercomputer Center           <*>  <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"



  parent reply	other threads:[~2002-07-16  8:18 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-13 19:10 if X in 1..35000 versus Boolean Jan Prazak
2002-07-13 16:27 ` Frank J. Lhota
2002-07-13 20:36   ` Jan Prazak
2002-07-13 18:05     ` Jeffrey Carter
2002-07-14 15:02       ` Jan Prazak
2002-07-13 22:10     ` Robert Dewar
2002-07-14 21:16       ` Jan Prazak
2002-07-14 20:47         ` Frank J. Lhota
2002-07-15  1:21         ` Jeffrey Carter
2002-07-16  8:18     ` Keith Thompson [this message]
2002-07-16 13:54       ` Jan Prazak
2002-07-16 11:13         ` Lutz Donnerhacke
2002-07-17 19:04           ` Jan Prazak
2002-07-17 20:00             ` Georg Bauhaus
2002-07-18  8:11             ` Lutz Donnerhacke
2002-07-18 14:39               ` Georg Bauhaus
2002-07-20  0:37               ` Robert Dewar
2002-07-16 20:25         ` Georg Bauhaus
2002-07-17 19:29           ` Jan Prazak
2002-07-16 19:24       ` Gautier
2002-07-17 19:04         ` Jan Prazak
2002-07-13 16:32 ` David C. Hoos, Sr.
2002-07-13 20:36   ` Jan Prazak
2002-07-13 18:02     ` David C. Hoos, Sr.
2002-07-13 18:17     ` sk
2002-07-13 20:02       ` Jeffrey Creem
     [not found]     ` <3D306ED5.33E80E09@myob.com>
2002-07-13 18:52       ` David C. Hoos, Sr.
     [not found]       ` <020a01c22a9f$2b50d6c0$6400000a@dhoos>
2002-07-13 19:02         ` sk
2002-07-14 15:02           ` Jan Prazak
2002-07-14 19:25             ` Darren New
2002-07-15 15:22               ` Steffen Huber
2002-07-13 16:44 ` Christopher Browne
2002-07-13 22:09   ` Robert Dewar
2002-07-13 17:17 ` tmoran
2002-07-13 19:44 ` Florian Weimer
  -- strict thread matches above, loose matches on Subject: below --
2002-07-14 20:22 Gautier direct_replies_not_read
2002-07-15 11:36 ` Jan Prazak
replies disabled

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