comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Concatenate enumeration
Date: Mon, 23 Nov 2009 18:21:06 -0500
Date: 2009-11-23T18:21:06-05:00	[thread overview]
Message-ID: <wcctywksu8t.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: heemov$1se$1@news.tornevall.net

"Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org> writes:

> Pablo wrote:
>> type Enumerate_Type is
>>   (
>>    NONE,
>>    READY
>>   );
>> for Enumerate_Type use
>>   (
>>    NONE  => 0,
>>    READY=> 1
>>   );
>> for Enumerate_Type'Size use 1;
>> and I want to create a new type Enumerate2_Type which could be the
>> form
>> type Enumerate_Type is
>>   (
>>    NONE,
>>    READY,
>>    OFF
>>   );
>> for Enumerate_Type use
>>   (
>>    NONE  => 0,
>>    READY=> 1,
>>    OFF     => 2
>>   );
>> for Enumerate_Type'Size use 2;

Note that all of the rep clauses above are unnecessary: the language
defines the default rep of enums to be (0, 1, ...),
and defines the 'Size to be 1 and 2 for the above.

If you want to confirm the 'Size, I'd do:

    pragma Assert (Enumerate_Type'Size = 1);

for example.

>> How to I do this without having to explicit clone the first one?
>
> You can't. Enumeration types are not extensible.

Extensible enumeration types were proposed for Ada 9X,
but were dropped.

> You can do something similar in the reverse direction:
>
> type Big is (None, Ready, Off);
>
> subtype Small is Big range None .. Ready;
>
> or
>
> type Small is new Big range None .. Ready;

Right.  And Big'Size = 2, and Small'Size = 1, by default.

- Bob



  reply	other threads:[~2009-11-23 23:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-23 18:15 Concatenate enumeration Pablo
2009-11-23 19:14 ` Jeffrey R. Carter
2009-11-23 23:21   ` Robert A Duff [this message]
2009-11-25 22:53     ` Randy Brukardt
2009-11-26  8:59       ` Dmitry A. Kazakov
2009-11-26  9:48         ` Georg Bauhaus
2009-11-26 10:03           ` Dmitry A. Kazakov
2009-11-24 19:42 ` Eryndlia Mavourneen
  -- strict thread matches above, loose matches on Subject: below --
2010-10-22 19:49 okellogg
2010-10-26  0:29 ` Yannick Duchêne (Hibou57)
2010-11-12 17:55 ` Randy Brukardt
replies disabled

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