comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: output of enumeration types
Date: Wed, 20 Apr 2005 11:53:38 +0200
Date: 2005-04-20T11:53:41+02:00	[thread overview]
Message-ID: <p6i9k1hxqwng$.1sjcqhuwk01z4.dlg@40tude.net> (raw)
In-Reply-To: d4472g$1ua$1@achot.icm.edu.pl

On Wed, 20 Apr 2005 02:17:26 +0200, Staszek Goldstein wrote:

> Uzytkownik "Stephen Leake" <stephen_leake@acm.org> napisal w wiadomosci 
> news:mailman.54.1113954069.24457.comp.lang.ada@ada-france.org...

>> As far as I can see, it is "just as easy". There is a package, that
>> someone wrote, that does text output for type String. Since you are
>> writing a new type, you need to write the output package for that as
>> well. Once that is done, both are "just as easy" for anyone else to
>> use.
>>
>> Note that Character has a special place in this discussion, since by
>> definition it is what gets written to a "text" file.
>>
>> So to do "output" with Roman_Number, you must specify some way to
>> convert its components to Character.
> 
> I do not feel convinced by the argument. If you want to write a number, you 
> can qualify it
> to be of some specific type and output it using, say, some instantiation of 
> the
> ada.text_io.integer_io package. Although the situation is very similar 
> here - I just want to be
> able to output character literals or arrays of such literals, I have no 
> generic package at
> my disposal and no possibility of converting them directly to the 
> "character" or "string" type.

What you refer are remnants of Ada 83 [flawed] approach which hopefully
someday will be replaced in a more OO way, where 'Image would become
object's attribute, dispatching and thus requiring no type specification in
any form. Note that generic instantiation (of Integer_IO etc) is a sort of
type specification.

>> Here's another tidbit that points out why "universal character" wont
>> solve this problem:
>>
>>   type Roman_Digit is (Foo,'V','X','L','C','D','M');
>>
>> is a perfectly legal type declaration!
> 
> I am not sure if this is really a problem. If 'V' is of a "universal 
> character type", then it is directly
> convertible to any character type which contains it as an enumeration 
> literal. Also, writing
> character(rm), where rm is a roman digit, should do no harm - this should 
> raise constraint_error
> or program_error if rm is not a character literal. More or less the same is 
> true of
> integer(long_int)... By the way, I have not experienced many applications of 
> the "mixed" types
> up to now.

Universal character as a common ancestor for all character type is a good
idea, but as Stephen has pointed out, it would not solve this particular
problem. You need a way to convey that Roman_Digit is a character type
derived from universal character. Presently Ada does not have character
class. Neither you can create a subtype of Character non-contiguous ranges
of characters (BTW, character maps might be what you are looking for.)
Further you'll need universal strings and the string class, also useful,
but non-existent in Ada. Too much work.

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



  reply	other threads:[~2005-04-20  9:53 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-18 22:04 output of enumeration types Staszek Goldstein
2005-04-18 22:35 ` Larry Kilgallen
2005-04-18 22:43   ` Staszek Goldstein
2005-04-18 23:35   ` Staszek Goldstein
2005-04-19  0:07     ` Stephen Leake
2005-04-19  0:43       ` Staszek Goldstein
2005-04-19  4:56         ` Martin Krischik
2005-04-19 18:57         ` Jeffrey Carter
2005-04-20  0:40           ` Staszek Goldstein
2005-04-20  1:38             ` Jeffrey Carter
2005-04-19  0:33     ` Larry Kilgallen
2005-04-19  0:51       ` Staszek Goldstein
2005-04-19 23:40         ` Stephen Leake
2005-04-20  0:17           ` Staszek Goldstein
2005-04-20  9:53             ` Dmitry A. Kazakov [this message]
2005-04-20 23:16             ` Stephen Leake
2005-04-19  0:59       ` Staszek Goldstein
2005-04-19  1:54 ` Robert A Duff
2005-04-19  3:03   ` Larry Kilgallen
2005-04-19 10:34   ` output and digits Staszek Goldstein
2005-04-20 13:56     ` Robert A Duff
2005-04-20 19:53       ` Staszek Goldstein
2005-04-19  3:04 ` output of enumeration types Steve
2005-04-19  7:31 ` Dmitry A. Kazakov
2005-04-19  7:49   ` Szymon Guz
2005-04-19  8:11     ` Dmitry A. Kazakov
2005-04-19 11:26     ` Marius Amado Alves
2005-04-19 12:56       ` Dmitry A. Kazakov
2005-04-19 13:57         ` Marius Amado Alves
2005-04-19 16:05       ` Larry Kilgallen
2005-04-19 17:55         ` Georg Bauhaus
2005-04-19 21:39           ` Florian Weimer
replies disabled

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