comp.lang.ada
 help / color / mirror / Atom feed
* Enumeration representation enhancement proposal
@ 2004-10-14  9:31 Wojtek Narczynski
  2004-10-14 17:47 ` Nick Roberts
  0 siblings, 1 reply; 7+ messages in thread
From: Wojtek Narczynski @ 2004-10-14  9:31 UTC (permalink / 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



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

end of thread, other threads:[~2004-10-20 11:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-14  9:31 Enumeration representation enhancement proposal Wojtek Narczynski
2004-10-14 17:47 ` 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

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