comp.lang.ada
 help / color / mirror / Atom feed
* Concatenate enumeration
@ 2009-11-23 18:15 Pablo
  2009-11-23 19:14 ` Jeffrey R. Carter
  2009-11-24 19:42 ` Eryndlia Mavourneen
  0 siblings, 2 replies; 11+ messages in thread
From: Pablo @ 2009-11-23 18:15 UTC (permalink / raw)


Hi, I have a enumerate type and I have another one which I want to add
some enumerations.
So:
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;

How to I do this without having to explicit clone the first one?
Thanks



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

* Re: Concatenate enumeration
  2009-11-23 18:15 Concatenate enumeration Pablo
@ 2009-11-23 19:14 ` Jeffrey R. Carter
  2009-11-23 23:21   ` Robert A Duff
  2009-11-24 19:42 ` Eryndlia Mavourneen
  1 sibling, 1 reply; 11+ messages in thread
From: Jeffrey R. Carter @ 2009-11-23 19:14 UTC (permalink / raw)


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;
> 
> How to I do this without having to explicit clone the first one?

You can't. Enumeration types are not extensible.

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;

-- 
Jeff Carter
"Monsieur Arthur King, who has the brain of a duck, you know."
Monty Python & the Holy Grail
09



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

* Re: Concatenate enumeration
  2009-11-23 19:14 ` Jeffrey R. Carter
@ 2009-11-23 23:21   ` Robert A Duff
  2009-11-25 22:53     ` Randy Brukardt
  0 siblings, 1 reply; 11+ messages in thread
From: Robert A Duff @ 2009-11-23 23:21 UTC (permalink / raw)


"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



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

* Re: Concatenate enumeration
  2009-11-23 18:15 Concatenate enumeration Pablo
  2009-11-23 19:14 ` Jeffrey R. Carter
@ 2009-11-24 19:42 ` Eryndlia Mavourneen
  1 sibling, 0 replies; 11+ messages in thread
From: Eryndlia Mavourneen @ 2009-11-24 19:42 UTC (permalink / raw)


On Nov 23, 1:15 pm, Pablo <pablit...@gmail.com> wrote:
> Hi, I have a enumerate type and I have another one which I want to add
> some enumerations.
> So:
> 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;
>
> How to I do this without having to explicit clone the first one?
> Thanks

It sounds as if you want the binary values of your enumerations to be
concatenated within a field.  You *can* do this by declaring a record
that has 2 fields, one for each enumeration.  You then can use a
representation clause to specify that the first type is contained in,
say, the first bit of the record and that the second type is contained
in the next 2 bits of the record.

This has the effect of concatenating the bit representations of the
types, but, of course, it does not concatenate the enumerations at the
Ada level, that is, the literals themselves.

Eryndlia



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

* Re: Concatenate enumeration
  2009-11-23 23:21   ` Robert A Duff
@ 2009-11-25 22:53     ` Randy Brukardt
  2009-11-26  8:59       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 11+ messages in thread
From: Randy Brukardt @ 2009-11-25 22:53 UTC (permalink / raw)


"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wcctywksu8t.fsf@shell01.TheWorld.com...
...
>> You can't. Enumeration types are not extensible.
>
> Extensible enumeration types were proposed for Ada 9X,
> but were dropped.

And were proposed again for Ada 2005, and were dropped again. See 
AI95-0261-1. I doubt it will ever be proposed again.

                        Randy.





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

* Re: Concatenate enumeration
  2009-11-25 22:53     ` Randy Brukardt
@ 2009-11-26  8:59       ` Dmitry A. Kazakov
  2009-11-26  9:48         ` Georg Bauhaus
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry A. Kazakov @ 2009-11-26  8:59 UTC (permalink / raw)


On Wed, 25 Nov 2009 16:53:07 -0600, Randy Brukardt wrote:

> "Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
> news:wcctywksu8t.fsf@shell01.TheWorld.com...
> ...
>>> You can't. Enumeration types are not extensible.
>>
>> Extensible enumeration types were proposed for Ada 9X,
>> but were dropped.
> 
> And were proposed again for Ada 2005, and were dropped again. See 
> AI95-0261-1. I doubt it will ever be proposed again.

These are different things. I think the OP didn't want an extensible type.
He wanted a new independent type constructed in some specific way.

To extend an enumeration type E that has to have the class (E'Class). This
is a lot of work.

To reuse names of the literals of E in some other type, you only need
reflection. E.g. an attribute, say, E'Domain, which would return
"universal-set" of its literals, then you could write:

   type E is (None, Ready);
   type E1 is E'Domain or (Off); -- = (None, Ready, Off)

Not very useful, but in other cases reflection could be very interesting.
For example, in generics:

   generic
      type T is array; -- Only this
   package ... is
      -- The [first] array index type would be T'Index (1)
      -- The array element type would be T'Element etc

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Concatenate enumeration
  2009-11-26  8:59       ` Dmitry A. Kazakov
@ 2009-11-26  9:48         ` Georg Bauhaus
  2009-11-26 10:03           ` Dmitry A. Kazakov
  0 siblings, 1 reply; 11+ messages in thread
From: Georg Bauhaus @ 2009-11-26  9:48 UTC (permalink / raw)


Dmitry A. Kazakov schrieb:

> Not very useful, but in other cases reflection could be very interesting.
> For example, in generics:
> 
>    generic
>       type T is array; -- Only this
>    package ... is
>       -- The [first] array index type would be T'Index (1)
>       -- The array element type would be T'Element etc
> 

I'm probably dense.  Is there a difference to what we have
now other than the unknown number of indexes of the array
type above?

   generic
       type T_Index is (<>);
       type T_Element is private;
       type T is array (T_Index range <>) of T_Element;
   package ... is



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

* Re: Concatenate enumeration
  2009-11-26  9:48         ` Georg Bauhaus
@ 2009-11-26 10:03           ` Dmitry A. Kazakov
  0 siblings, 0 replies; 11+ messages in thread
From: Dmitry A. Kazakov @ 2009-11-26 10:03 UTC (permalink / raw)


On Thu, 26 Nov 2009 10:48:24 +0100, Georg Bauhaus wrote:

> Dmitry A. Kazakov schrieb:
> 
>> Not very useful, but in other cases reflection could be very interesting.
>> For example, in generics:
>> 
>>    generic
>>       type T is array; -- Only this
>>    package ... is
>>       -- The [first] array index type would be T'Index (1)
>>       -- The array element type would be T'Element etc
>> 
> 
> I'm probably dense.  Is there a difference to what we have
> now other than the unknown number of indexes of the array
> type above?
> 
>    generic
>        type T_Index is (<>);
>        type T_Element is private;
>        type T is array (T_Index range <>) of T_Element;
>    package ... is

The difference is in the number of formal parameters.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Concatenate enumeration
@ 2010-10-22 19:49 okellogg
  2010-10-26  0:29 ` Yannick Duchêne (Hibou57)
  2010-11-12 17:55 ` Randy Brukardt
  0 siblings, 2 replies; 11+ messages in thread
From: okellogg @ 2010-10-22 19:49 UTC (permalink / raw)


In https://groups.google.com/group/comp.lang.ada/browse_thread/thread/33ce43bfeafb2681/237f979efee731d3,
Randy Brukardt wrote:

> "Robert A Duff" <bobd...@shell01.TheWorld.com> wrote in message
> news:wcctywksu8t.fsf@shell01.TheWorld.com...
> ...
>
> >> You can't. Enumeration types are not extensible.
>
> > Extensible enumeration types were proposed for Ada 9X,
> > but were dropped.
>
> And were proposed again for Ada 2005, and were dropped again. See
> AI95-0261-1. I doubt it will ever be proposed again.

I wonder why this has not been picked up - especially when looking at
all the new features that are making it into Ada2012.

Oliver



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

* Re: Concatenate enumeration
  2010-10-22 19:49 okellogg
@ 2010-10-26  0:29 ` Yannick Duchêne (Hibou57)
  2010-11-12 17:55 ` Randy Brukardt
  1 sibling, 0 replies; 11+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2010-10-26  0:29 UTC (permalink / raw)


Le Fri, 22 Oct 2010 21:49:26 +0200, okellogg  
<okellogg@users.sourceforge.net> a écrit:

> In  
> https://groups.google.com/group/comp.lang.ada/browse_thread/thread/33ce43bfeafb2681/237f979efee731d3,
> Randy Brukardt wrote:
>
>> "Robert A Duff" <bobd...@shell01.TheWorld.com> wrote in message
>> news:wcctywksu8t.fsf@shell01.TheWorld.com...
>> ...
>>
>> >> You can't. Enumeration types are not extensible.
>>
>> > Extensible enumeration types were proposed for Ada 9X,
>> > but were dropped.
>>
>> And were proposed again for Ada 2005, and were dropped again. See
>> AI95-0261-1. I doubt it will ever be proposed again.
>
> I wonder why this has not been picked up - especially when looking at
> all the new features that are making it into Ada2012.
>
> Oliver
I remember I made the same request when I felt it would be nice to be able  
to extend an enumeration in multiple client packages, just like the way  
you can extend a tagged record with additional members. Otherwise, I had  
to declare all items of the enumeration, including many ones which was  
meaning nothing in the context of the root package, or else had to  
simulate enumeration extension in a tedious and not clean way (with  
incompatible types, awkward conversion based on 'Pos / 'Val, and the like).

-- 
Si les chats miaulent et font autant de vocalises bizarres, c’est pas pour  
les chiens.



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

* Re: Concatenate enumeration
  2010-10-22 19:49 okellogg
  2010-10-26  0:29 ` Yannick Duchêne (Hibou57)
@ 2010-11-12 17:55 ` Randy Brukardt
  1 sibling, 0 replies; 11+ messages in thread
From: Randy Brukardt @ 2010-11-12 17:55 UTC (permalink / raw)


"okellogg" <okellogg@users.sourceforge.net> wrote in message 
news:0ff42bdb-63a1-4fc2-bb44-e8d89a82bc68@j18g2000yqd.googlegroups.com...
> In 
> https://groups.google.com/group/comp.lang.ada/browse_thread/thread/33ce43bfeafb2681/237f979efee731d3,
> Randy Brukardt wrote:
>
>> "Robert A Duff" <bobd...@shell01.TheWorld.com> wrote in message
>> news:wcctywksu8t.fsf@shell01.TheWorld.com...
>> ...
>>
>> >> You can't. Enumeration types are not extensible.
>>
>> > Extensible enumeration types were proposed for Ada 9X,
>> > but were dropped.
>>
>> And were proposed again for Ada 2005, and were dropped again. See
>> AI95-0261-1. I doubt it will ever be proposed again.
>
> I wonder why this has not been picked up - especially when looking at
> all the new features that are making it into Ada2012.

The semantic difficulties are staggering. It just doesn't make sense in the 
Ada model of types (mostly because of the Ada requirement that enumerations 
be elementary types). Some solution to the problems probably could be found, 
but the obvious ones make the extensions near useless. Go read AI95-0261-1 
if you care about the details.

                                         Randy.





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

end of thread, other threads:[~2010-11-12 17:55 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-23 18:15 Concatenate enumeration Pablo
2009-11-23 19:14 ` Jeffrey R. Carter
2009-11-23 23:21   ` Robert A Duff
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

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