comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nick.roberts@acm.org>
Subject: Re: Enumeration representation enhancement proposal
Date: Thu, 14 Oct 2004 18:47:19 +0100
Date: 2004-10-14T18:47:19+01:00	[thread overview]
Message-ID: <2t7sd8F1rsqh9U1@uni-berlin.de> (raw)
In-Reply-To: <pan.2004.10.14.09.31.37.373508@power.com.pl>

Wojtek Narczynski wrote:

> Enumeration representation in their current form are not very useful,
> because there is no treatment of invalid values. That's why constants,
> and constant to enum mapping arrays are used so heavily in real
> interfacing code.

I tentatively agree with this sentiment. However, I suspect that making
enumeration types more 'useful' could be difficult.

> Invalid external values are rather norm than exception, thus they
> deserve 'non-exceptional' treatment. The 'Valid attribute alleviates
> the problem, but it is not very convenient, for example won't work in
> case statements, it requires to have two different ways to log the
> value (valid and invalid).
> 
> Maybe this could be improved in Ada 2005? For example:
> 
> type Mix_Code is (Red, Green, Blue, Grey);
> 
> --  Modest proposal
> 
> for Mix_Code use (Red => 1, Green => 2, Blue => 3, Grey => others);
> 
> This should be relatively straightforward to implement, and would cover
> most needs.

The problem with this proposal it that (actual) values of the type would
no longer satisfy the ordering criteria (that a machine < or > test will
always have the same result as the corresponding canonical test).

> However...
> 
> --  Die-hard proposal
> 
> for Mix_Code use
>   (Red => 1 | 10, Green => 11 .. 20, Blue => 21 .. 30 | 40, Grey => others);
> 
> An unambiguous mapping from the rep value to Ada enum would be required,
> not the other direction.

This idea seems to stir up a hornet's nest of difficulties. I also suspect
that if the ordering property were still required, it wouldn't often be
useful in practice. I think I'd rather construct a type with explicit
operations to deal with this sort of situation; this approach does give
complete control over the translation between (actual) value and meaning.

But this is just my opinion!

Unfortunately, I believe it is now too late for any new proposals for
Ada 2005. I think there is just one more ARG meeting before they must put
their recommendation to WG9 (the committee of representatives of the
respective members of ISO delegated to deal with the Ada language). WG9
will vote on each amendment proposal, and they will (almost certainly)
reject any proposal that they feel has not been properly developed. (In
other words, crunch time.) I'm not quite sure about the schedule TBH.

-- 
Nick Roberts



  reply	other threads:[~2004-10-14 17:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-14  9:31 Enumeration representation enhancement proposal Wojtek Narczynski
2004-10-14 17:47 ` Nick Roberts [this message]
2004-10-15 11:06   ` Wojtek Narczynski
2004-10-19 14:55     ` Jacob Sparre Andersen
2004-10-20  8:41       ` Wojtek Narczynski
2004-10-20  8:58         ` Jacob Sparre Andersen
2004-10-20 11:04           ` Wojtek Narczynski
replies disabled

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