comp.lang.ada
 help / color / mirror / Atom feed
From: Wojtek Narczynski <wojtek@power.com.pl>
Subject: Enumeration representation enhancement proposal
Date: Thu, 14 Oct 2004 11:31:38 +0200
Date: 2004-10-14T11:31:38+02:00	[thread overview]
Message-ID: <pan.2004.10.14.09.31.37.373508@power.com.pl> (raw)

Hello,

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.

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.

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.

Regards,
Wojtek



             reply	other threads:[~2004-10-14  9:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-14  9:31 Wojtek Narczynski [this message]
2004-10-14 17:47 ` Enumeration representation enhancement proposal Nick Roberts
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