comp.lang.ada
 help / color / mirror / Atom feed
* output of enumeration types
@ 2005-04-18 22:04 Staszek Goldstein
  2005-04-18 22:35 ` Larry Kilgallen
                   ` (3 more replies)
  0 siblings, 4 replies; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-18 22:04 UTC (permalink / raw)


I have got the following problem: having defined
type roman_digit is ('I','V','X','L','C','D','M');
type roman_number is array (positive range <>) of roman_digit;
I want to print, say, "MMV" of type roman_number on the standard output. I 
have no idea how to do it, at least without tedious step-by-step conversion 
routines between roman numbers and strings.Can you help me? 





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

* Re: output of enumeration types
  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  1:54 ` Robert A Duff
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 32+ messages in thread
From: Larry Kilgallen @ 2005-04-18 22:35 UTC (permalink / raw)


In article <d41ars$3eo$1@achot.icm.edu.pl>, "Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:
> I have got the following problem: having defined
> type roman_digit is ('I','V','X','L','C','D','M');
> type roman_number is array (positive range <>) of roman_digit;
> I want to print, say, "MMV" of type roman_number on the standard output. I 
> have no idea how to do it, at least without tedious step-by-step conversion 
> routines between roman numbers and strings.

What is tedious ?  The computer will do it for you.

If there were a built-in Make_Roman function, the computer would still
be doing the work.



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

* Re: output of enumeration types
  2005-04-18 22:35 ` Larry Kilgallen
@ 2005-04-18 22:43   ` Staszek Goldstein
  2005-04-18 23:35   ` Staszek Goldstein
  1 sibling, 0 replies; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-18 22:43 UTC (permalink / raw)


The computre will not change roman digit to character - they are 
incompatible types! 





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

* Re: output of enumeration types
  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:33     ` Larry Kilgallen
  1 sibling, 2 replies; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-18 23:35 UTC (permalink / raw)


Maybe I should make myself clearer. I find it very inelegant to write 
something like:
function conversion(rm: roman_digit) return character is
begin
    case rm is
        when 'I' => retunrn 'I';
        when 'V'=>retrun 'V';
and so on, and then to construct a routine for conversion of a roman number 
to a string using the function. Is there any better way? 





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

* Re: output of enumeration types
  2005-04-18 23:35   ` Staszek Goldstein
@ 2005-04-19  0:07     ` Stephen Leake
  2005-04-19  0:43       ` Staszek Goldstein
  2005-04-19  0:33     ` Larry Kilgallen
  1 sibling, 1 reply; 32+ messages in thread
From: Stephen Leake @ 2005-04-19  0:07 UTC (permalink / raw)
  To: Staszek Goldstein; +Cc: comp.lang.ada

"Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:

> Maybe I should make myself clearer. I find it very inelegant to write 
> something like:
> function conversion(rm: roman_digit) return character is
> begin
>     case rm is
>         when 'I' => retunrn 'I';
>         when 'V'=>retrun 'V';
> and so on, and then to construct a routine for conversion of a roman number 
> to a string using the function. Is there any better way? 

Use a constant array:

with Ada.Text_Io;
procedure Roman
is
   type Roman_Digit is ('I','V','X','L','C','D','M');
   type Roman_Number is array (positive range <>) of roman_digit;

   Roman_Character_Map : constant array (Roman_Digit) of Character :=
     ('I' => 'I',
      'V' => 'V',
      'X' => 'X',
      'L' => 'L',
      'C' => 'C',
      'D' => 'D',
      'M' => 'M');

   function To_String (Item : in Roman_Number) return String
   is
      Result : String (Item'Range);
   begin
      for I in Item'Range loop
         Result (I) := Roman_Character_Map (Item (I));
      end loop;
      return Result;
   end To_String;

   A : Roman_Number := "MMV";
begin
   Ada.Text_Io.Put_Line ("MMV => " & To_String (A));
end Roman;

-- 
-- Stephe




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

* Re: output of enumeration types
  2005-04-18 23:35   ` Staszek Goldstein
  2005-04-19  0:07     ` Stephen Leake
@ 2005-04-19  0:33     ` Larry Kilgallen
  2005-04-19  0:51       ` Staszek Goldstein
  2005-04-19  0:59       ` Staszek Goldstein
  1 sibling, 2 replies; 32+ messages in thread
From: Larry Kilgallen @ 2005-04-19  0:33 UTC (permalink / raw)


In article <d41g8c$a16$1@achot.icm.edu.pl>, "Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:
> Maybe I should make myself clearer. I find it very inelegant to write 
> something like:
> function conversion(rm: roman_digit) return character is
> begin
>     case rm is
>         when 'I' => retunrn 'I';
>         when 'V'=>retrun 'V';
> and so on,

	roman_digit'image ( rm )

should give you a single character string.



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

* Re: output of enumeration types
  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
  0 siblings, 2 replies; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-19  0:43 UTC (permalink / raw)


Thanks for the idea, it is slightly more elegant than my solution. 
Nevertheless, I have the impression that this is a deficiency of Ada which 
should be dealt with. A solution could be kind of "universal_character" 
type, freely convertible to any character type. 





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

* Re: output of enumeration types
  2005-04-19  0:33     ` Larry Kilgallen
@ 2005-04-19  0:51       ` Staszek Goldstein
  2005-04-19 23:40         ` Stephen Leake
  2005-04-19  0:59       ` Staszek Goldstein
  1 sibling, 1 reply; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-19  0:51 UTC (permalink / raw)


This is also a nice idea, although for converting a string you still need a 
function like the one given by Stephen Leake. It seems to me that it should 
be possible to output the roman number as easily as it is to output a 
string - there is no difference between the literals, they both look exactly 
the same. 





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

* Re: output of enumeration types
  2005-04-19  0:33     ` Larry Kilgallen
  2005-04-19  0:51       ` Staszek Goldstein
@ 2005-04-19  0:59       ` Staszek Goldstein
  1 sibling, 0 replies; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-19  0:59 UTC (permalink / raw)


One more remark: roman_digit'image(rm) is a string of 3 characters.  So, for 
example, writing the function converting a roman number to a string requires 
something like: s(i):=roman_digit'image(rm(i))(2) inside. 





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

* Re: output of enumeration types
  2005-04-18 22:04 output of enumeration types Staszek Goldstein
  2005-04-18 22:35 ` Larry Kilgallen
@ 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-19  3:04 ` output of enumeration types Steve
  2005-04-19  7:31 ` Dmitry A. Kazakov
  3 siblings, 2 replies; 32+ messages in thread
From: Robert A Duff @ 2005-04-19  1:54 UTC (permalink / raw)


"Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:

> I have got the following problem: having defined
> type roman_digit is ('I','V','X','L','C','D','M');
> type roman_number is array (positive range <>) of roman_digit;
> I want to print, say, "MMV" of type roman_number on the standard output. I 
> have no idea how to do it, at least without tedious step-by-step conversion 
> routines between roman numbers and strings.Can you help me? 

You can convert a Roman_Digit to a Character via
Character'Value(Roman_Digit'Image(X)).  You can write a function to
convert Roman_Number to String, using that in a loop.
That's not very efficient, but it avoids the tedious mentioning
of every Roman_Digit character in the conversion routine.

But you can use the same technique to populate a table
(a constant array, indexed by Roman_Digit, of Character),
and use that for quick conversion of Roman_Digits to Characters.
And write the Roman_Number-to-String function using that table.

Then output is just "Text_IO.Put(To_String(Whatever))".

By the way, "Roman_Digit" is a strange name -- in what sense are these
symbols "digits"?

----------------

Here's another idea:

    type Roman_Digit is ('I','V','X','L','C','D','M');
    for Roman_Digit use ('I' => Character'('I')'val,
                         'V' => ...);

Then Unchecked_Conversion from Roman_Digit to Character will work.

Except that you then need to order the Roman_Digits in the same
order as in Character: "... is ('C', 'D', ..., 'X')".

And Unchecked_Conversion the other way 'round is dangerous....

- Bob



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

* Re: output of enumeration types
  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
  1 sibling, 0 replies; 32+ messages in thread
From: Larry Kilgallen @ 2005-04-19  3:03 UTC (permalink / raw)


In article <wccmzrvfs4i.fsf@shell01.TheWorld.com>, Robert A Duff <bobduff@shell01.TheWorld.com> writes:

> By the way, "Roman_Digit" is a strange name -- in what sense are these
> symbols "digits"?

It makes sense to me -- it takes a whole string of them to make a "number".



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

* Re: output of enumeration types
  2005-04-18 22:04 output of enumeration types Staszek Goldstein
  2005-04-18 22:35 ` Larry Kilgallen
  2005-04-19  1:54 ` Robert A Duff
@ 2005-04-19  3:04 ` Steve
  2005-04-19  7:31 ` Dmitry A. Kazakov
  3 siblings, 0 replies; 32+ messages in thread
From: Steve @ 2005-04-19  3:04 UTC (permalink / raw)


It doesn't look that tedious to me:

   function To_String( Value : Roman_Number ) return String is
       result : String( Value'range );
   begin
       for idx in Value'range loop
           result( idx ) := Roman_Digit'Image( Value( idx ) )(2);
       end loop;
       return result;
   end To_String;

... and please say that this is not a homework assignment.

Steve
(The Duck)

"Staszek Goldstein" <goldstei@math.uni.lodz.pl> wrote in message 
news:d41ars$3eo$1@achot.icm.edu.pl...
>I have got the following problem: having defined
> type roman_digit is ('I','V','X','L','C','D','M');
> type roman_number is array (positive range <>) of roman_digit;
> I want to print, say, "MMV" of type roman_number on the standard output. I 
> have no idea how to do it, at least without tedious step-by-step 
> conversion routines between roman numbers and strings.Can you help me?
> 





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

* Re: output of enumeration types
  2005-04-19  0:43       ` Staszek Goldstein
@ 2005-04-19  4:56         ` Martin Krischik
  2005-04-19 18:57         ` Jeffrey Carter
  1 sibling, 0 replies; 32+ messages in thread
From: Martin Krischik @ 2005-04-19  4:56 UTC (permalink / raw)


Staszek Goldstein wrote:

> Thanks for the idea, it is slightly more elegant than my solution.
> Nevertheless, I have the impression that this is a deficiency of Ada which
> should be dealt with. A solution could be kind of "universal_character"
> type, freely convertible to any character type.

Well, at least Ada has user definable Character types - which other
languages don't have.

As for the "universal_character"  approach, have you considered the
implication of:

type roman_digit is ('I','V','X','L','C','D','M');
for roman_digit'Size use 3;

You see Character and roman_digit are not directly convertible because they
*might* be of different size. And a "universal_character" would need to be
16 bit (32 with Ada 2005*) because of Wide_Character (Wide_Wide_Character
in Ada 2005*).

Martin

* Or perhaps Ada 2006 - the new standart isn't written in stone yet.
-- 
mailto://krischik@users.sourceforge.net
Ada programming at: http://ada.krischik.com




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

* Re: output of enumeration types
  2005-04-18 22:04 output of enumeration types Staszek Goldstein
                   ` (2 preceding siblings ...)
  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
  3 siblings, 1 reply; 32+ messages in thread
From: Dmitry A. Kazakov @ 2005-04-19  7:31 UTC (permalink / raw)


On Tue, 19 Apr 2005 00:04:04 +0200, Staszek Goldstein wrote:

> I have got the following problem: having defined
> type roman_digit is ('I','V','X','L','C','D','M');
> type roman_number is array (positive range <>) of roman_digit;

But Roman number is not an array of letters. As others have pointed out 'I'
is not a digit. It can represent or not a decimal position depending on the
context. For example in 'XIII', the "digits" are 'X' and 'III'. Anyway it
should rather be:

type Roman_Number is range 1..3999;

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



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

* Re: output of enumeration types
  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
  0 siblings, 2 replies; 32+ messages in thread
From: Szymon Guz @ 2005-04-19  7:49 UTC (permalink / raw)


Dmitry A. Kazakov napisaďż˝(a):
> On Tue, 19 Apr 2005 00:04:04 +0200, Staszek Goldstein wrote:
> 
> 
>>I have got the following problem: having defined
>>type roman_digit is ('I','V','X','L','C','D','M');
>>type roman_number is array (positive range <>) of roman_digit;
> 
> 
> But Roman number is not an array of letters. As others have pointed out 'I'
> is not a digit. It can represent or not a decimal position depending on the
> context. For example in 'XIII', the "digits" are 'X' and 'III'. Anyway it
> should rather be:
> 
> type Roman_Number is range 1..3999;
> 

Well, I can't see your point, why 1..3999 ?

regards
Szymon Guz



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

* Re: output of enumeration types
  2005-04-19  7:49   ` Szymon Guz
@ 2005-04-19  8:11     ` Dmitry A. Kazakov
  2005-04-19 11:26     ` Marius Amado Alves
  1 sibling, 0 replies; 32+ messages in thread
From: Dmitry A. Kazakov @ 2005-04-19  8:11 UTC (permalink / raw)


On Tue, 19 Apr 2005 09:49:41 +0200, Szymon Guz wrote:

> Dmitry A. Kazakov napisaďż˝(a):

>> On Tue, 19 Apr 2005 00:04:04 +0200, Staszek Goldstein wrote:
>> 
>>>I have got the following problem: having defined
>>>type roman_digit is ('I','V','X','L','C','D','M');
>>>type roman_number is array (positive range <>) of roman_digit;
>> 
>> But Roman number is not an array of letters. As others have pointed out 'I'
>> is not a digit. It can represent or not a decimal position depending on the
>> context. For example in 'XIII', the "digits" are 'X' and 'III'. Anyway it
>> should rather be:
>> 
>> type Roman_Number is range 1..3999;
> 
> Well, I can't see your point, why 1..3999 ?

Because Romans knew neither zero nor negative numbers and 3999 is the
maximal number that can be represented using I,V,X,L,C,D,M: 3999=MMMCMXCIX.
Honestly I don't know how they managed to build a great empire with that!
(:-))

[ http://www.dmitry-kazakov.de/ada/strings_edit.htm contains an
implementation of Roman numbers I/O. ]

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



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

* output and digits
  2005-04-19  1:54 ` Robert A Duff
  2005-04-19  3:03   ` Larry Kilgallen
@ 2005-04-19 10:34   ` Staszek Goldstein
  2005-04-20 13:56     ` Robert A Duff
  1 sibling, 1 reply; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-19 10:34 UTC (permalink / raw)


> You can convert a Roman_Digit to a Character via
> Character'Value(Roman_Digit'Image(X)).  You can write a function to
> convert Roman_Number to String, using that in a loop.
> That's not very efficient, but it avoids the tedious mentioning
> of every Roman_Digit character in the conversion routine.

This seems like a best idea so far...

> By the way, "Roman_Digit" is a strange name -- in what sense are these
> symbols "digits"?
>

This is not a strange name - it is a very good name. A completely disagree
also with Dmitry's claim that there are only two digits in
"VIII" - there are four. In Dmitry's sense something may be a digit or not
depending on its position in the number (for example, in"MCM" the first 'M'
is a digit, and the second not). Although nothing prevents us from adopting
such a point of vue, it seems very unnatural."Numbers" are words over an
alphabet consisting of digits as much as usual "words" are words over an
alphabet consisting of letters. As such, digits may have no semantics. For
example, "101" can denote number 101 and number 3, and many others. So the
value of a string of digits depends on the way we interpret it.

>    type Roman_Digit is ('I','V','X','L','C','D','M');
>    for Roman_Digit use ('I' => Character'('I')'val,
>                         'V' => ...);
>
> Then Unchecked_Conversion from Roman_Digit to Character will work.
> Except that you then need to order the Roman_Digits in the same
> order as in Character: "... is ('C', 'D', ..., 'X')".

This works (if you correct it slightly to integer(character'pos('I')) - pos
gives a universal integer!), but changing the order does not seem nice in a
language like Ada...

Thanks to everybody,
Staszek








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

* Re: output of enumeration types
  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 16:05       ` Larry Kilgallen
  1 sibling, 2 replies; 32+ messages in thread
From: Marius Amado Alves @ 2005-04-19 11:26 UTC (permalink / raw)
  To: comp.lang.ada

>> ... 'I'
>> is not a digit. It can represent or not a decimal position depending 
>> on the
>> context. For example in 'XIII', the "digits" are 'X' and 'III'.

This is rubbish. There are no "decimal positions" in Roman numbers. If 
there were, XIII = 103, not 13, IV = 15, not 4.

"Digit" does not necessarily convey position. It is a notion, not some 
engineering standard. It is OK to call 'X', 'I', "Roman digits." 
However the canonical name is "characters," I think.

And, Dmitry, larger numbers than 3999 could be written: a slash over 
the character multiplies by 1000. A job for Unicode I guess...




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

* Re: output of enumeration types
  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
  1 sibling, 1 reply; 32+ messages in thread
From: Dmitry A. Kazakov @ 2005-04-19 12:56 UTC (permalink / raw)


On Tue, 19 Apr 2005 12:26:25 +0100, Marius Amado Alves wrote:

>>> ... 'I'
>>> is not a digit. It can represent or not a decimal position depending 
>>> on the
>>> context. For example in 'XIII', the "digits" are 'X' and 'III'.
> 
> This is rubbish. There are no "decimal positions" in Roman numbers. If 
> there were, XIII = 103, not 13, IV = 15, not 4.

Positions are counted in digits /= characters! Otherwise "forty five" would
be 40005 (:-))

No, actually Roman system is almost decimal positional, I am using this in
my software. Decimal digits are:

0=<empty>
1=a,
2=aa,
3=aaa,
4=ab,
5=b,
6=ba,
7=baa,
8=baaa,
9=ac 

Characters in the triplet a, b, c change their spelling with the position:

   a b c -->
1x I V X,
10x X L C,
100x C D M
1000x M - -

Only absence of a non-empty digit for 0 prevented Romans from noticing that
there is no any need in changing spelling according to the position.

> "Digit" does not necessarily convey position. It is a notion, not some 
> engineering standard. It is OK to call 'X', 'I', "Roman digits." 
> However the canonical name is "characters," I think.
> 
> And, Dmitry, larger numbers than 3999 could be written: a slash over 
> the character multiplies by 1000. A job for Unicode I guess...

Wasn't it a medieval vulgarization?

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



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

* Re: output of enumeration types
  2005-04-19 12:56       ` Dmitry A. Kazakov
@ 2005-04-19 13:57         ` Marius Amado Alves
  0 siblings, 0 replies; 32+ messages in thread
From: Marius Amado Alves @ 2005-04-19 13:57 UTC (permalink / raw)
  To: comp.lang.ada

> No, actually Roman system is almost decimal positional...

Ok, "almost."  To me relative positions meaning addition and 
subtraction mingled with decimal positions is a big "almost", but ok.

> Wasn't it a medieval vulgarization?

No. Later Republic. Before that they resorted to Chalcidic symbols for 
5_000, 10_000, 50_000, 100_000, etc.




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

* Re: output of enumeration types
  2005-04-19 11:26     ` Marius Amado Alves
  2005-04-19 12:56       ` Dmitry A. Kazakov
@ 2005-04-19 16:05       ` Larry Kilgallen
  2005-04-19 17:55         ` Georg Bauhaus
  1 sibling, 1 reply; 32+ messages in thread
From: Larry Kilgallen @ 2005-04-19 16:05 UTC (permalink / raw)


In article <mailman.48.1113910014.24457.comp.lang.ada@ada-france.org>, Marius Amado Alves <amado.alves@netcabo.pt> writes:

> "Digit" does not necessarily convey position. It is a notion, not some 
> engineering standard. It is OK to call 'X', 'I', "Roman digits." 
> However the canonical name is "characters," I think.

But "E" is a roman "character".



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

* Re: output of enumeration types
  2005-04-19 16:05       ` Larry Kilgallen
@ 2005-04-19 17:55         ` Georg Bauhaus
  2005-04-19 21:39           ` Florian Weimer
  0 siblings, 1 reply; 32+ messages in thread
From: Georg Bauhaus @ 2005-04-19 17:55 UTC (permalink / raw)


Larry Kilgallen wrote:
> In article <mailman.48.1113910014.24457.comp.lang.ada@ada-france.org>, Marius Amado Alves <amado.alves@netcabo.pt> writes:
> 
> 
>>"Digit" does not necessarily convey position. It is a notion, not some 
>>engineering standard. It is OK to call 'X', 'I', "Roman digits." 
>>However the canonical name is "characters," I think.
> 
> 
> But "E" is a roman "character".

http://mathforum.org/dr.math/faq/faq.roman.html
says "numerals" or "letters". How does Knuth name them?



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

* Re: output of enumeration types
  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
  1 sibling, 1 reply; 32+ messages in thread
From: Jeffrey Carter @ 2005-04-19 18:57 UTC (permalink / raw)


Staszek Goldstein wrote:

> Thanks for the idea, it is slightly more elegant than my solution. 
> Nevertheless, I have the impression that this is a deficiency of Ada which 
> should be dealt with. A solution could be kind of "universal_character" 
> type, freely convertible to any character type. 

Implement your Roman numbers problem in another, widely used, imperative 
language, preferably one from the C family, first. Then come back and do 
it in Ada. Let us know if you still have complaints about Ada's support 
for this kind of thing.

-- 
Jeff Carter
"Help! Help! I'm being repressed!"
Monty Python & the Holy Grail
67



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

* Re: output of enumeration types
  2005-04-19 17:55         ` Georg Bauhaus
@ 2005-04-19 21:39           ` Florian Weimer
  0 siblings, 0 replies; 32+ messages in thread
From: Florian Weimer @ 2005-04-19 21:39 UTC (permalink / raw)


* Georg Bauhaus:

> http://mathforum.org/dr.math/faq/faq.roman.html
> says "numerals" or "letters". How does Knuth name them?

TeX provides a \romannumeral primitive.



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

* Re: output of enumeration types
  2005-04-19  0:51       ` Staszek Goldstein
@ 2005-04-19 23:40         ` Stephen Leake
  2005-04-20  0:17           ` Staszek Goldstein
  0 siblings, 1 reply; 32+ messages in thread
From: Stephen Leake @ 2005-04-19 23:40 UTC (permalink / raw)
  To: Staszek Goldstein; +Cc: comp.lang.ada

"Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:

> This 

please quote enough so we can tell what you are refering to.

> is also a nice idea, although for converting a string you still need
> a function like the one given by Stephen Leake. It seems to me that
> it should be possible to output the roman number as easily as it is
> to output a string - there is no difference between the literals,
> they both look exactly the same.

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.

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!

-- 
-- Stephe




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

* Re: output of enumeration types
  2005-04-19 23:40         ` Stephen Leake
@ 2005-04-20  0:17           ` Staszek Goldstein
  2005-04-20  9:53             ` Dmitry A. Kazakov
  2005-04-20 23:16             ` Stephen Leake
  0 siblings, 2 replies; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-20  0:17 UTC (permalink / raw)



Uzytkownik "Stephen Leake" <stephen_leake@acm.org> napisal w wiadomosci 
news:mailman.54.1113954069.24457.comp.lang.ada@ada-france.org...
> "Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:
>
>> This
>
> please quote enough so we can tell what you are refering to.

My letter was an answer to a specific message containing just one idea.

>> is also a nice idea, although for converting a string you still need
>> a function like the one given by Stephen Leake. It seems to me that
>> it should be possible to output the roman number as easily as it is
>> to output a string - there is no difference between the literals,
>> they both look exactly the same.
>
> 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.

> 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.

Staszek 





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

* Re: output of enumeration types
  2005-04-19 18:57         ` Jeffrey Carter
@ 2005-04-20  0:40           ` Staszek Goldstein
  2005-04-20  1:38             ` Jeffrey Carter
  0 siblings, 1 reply; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-20  0:40 UTC (permalink / raw)



Uzytkownik "Jeffrey Carter" <spam@spam.com> napisal w wiadomosci 
news:Mwc9e.10836$lP1.5710@newsread1.news.pas.earthlink.net...
> Staszek Goldstein wrote:
>
>> Thanks for the idea, it is slightly more elegant than my solution. 
>> Nevertheless, I have the impression that this is a deficiency of Ada 
>> which should be dealt with. A solution could be kind of 
>> "universal_character" type, freely convertible to any character type.
>
> Implement your Roman numbers problem in another, widely used, imperative 
> language, preferably one from the C family, first. Then come back and do 
> it in Ada. Let us know if you still have complaints about Ada's support 
> for this kind of thing.

I am afraid this is just the kind of argument that makes Ada so unpopular 
(no offence
intended). The point is that Ada delivers lots of beautiful abstractions, 
but people
are often quite happy with something less abstract and easier to use. For
example, I would have no difficulty dealing with the problem in C because I
would not have even dreamt of building the type in C - I would have used
regular strings instead. You use abstractions to solve problems, not to 
create
them.

As an example, look at the changes for the Next Ada. There are some great
ideas which make life easier for the programmers, like anonymous access 
types, removing
the need for some type conversions during OOP, adding support for unbounded 
strings and
so on. On the other hand, we shall still have to deal with the "constructor 
problem" and learn
the many great ways of dealing with it instead of getting rid of the problem 
altogether.
Similarly, we will have no gnat.io package, instead our students (who are 
not English or
American) will loose time trying to figure out where to put a dot and where 
an underscore
in ada.integer_text_io. Ada, while gaining power, lost some of its virtues 
as a language
"easy to read" without becoming "easier to write".

Staszek 





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

* Re: output of enumeration types
  2005-04-20  0:40           ` Staszek Goldstein
@ 2005-04-20  1:38             ` Jeffrey Carter
  0 siblings, 0 replies; 32+ messages in thread
From: Jeffrey Carter @ 2005-04-20  1:38 UTC (permalink / raw)


Staszek Goldstein wrote:
> 
> I am afraid this is just the kind of argument that makes Ada so unpopular 
> (no offence
> intended). The point is that Ada delivers lots of beautiful abstractions, 
> but people
> are often quite happy with something less abstract and easier to use. For
> example, I would have no difficulty dealing with the problem in C because I
> would not have even dreamt of building the type in C - I would have used
> regular strings instead. You use abstractions to solve problems, not to 
> create
> them.

I would have no difficulty dealing with the problem in Ada. Yes, I would 
have to write some code to deal with the character and string types 
involved, but it would be a lot less than the amount of code I would 
need to deal with the concepts in C.

> Ada, while gaining power, lost some of its virtues 
> as a language
> "easy to read" without becoming "easier to write".

Emphasizing ease of reading over ease of writing is an explicit design 
goal for Ada. Ada is a language for software engineers. "Easier to 
write" is only important for coders.

-- 
Jeff Carter
"Help! Help! I'm being repressed!"
Monty Python & the Holy Grail
67



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

* Re: output of enumeration types
  2005-04-20  0:17           ` Staszek Goldstein
@ 2005-04-20  9:53             ` Dmitry A. Kazakov
  2005-04-20 23:16             ` Stephen Leake
  1 sibling, 0 replies; 32+ messages in thread
From: Dmitry A. Kazakov @ 2005-04-20  9:53 UTC (permalink / raw)


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



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

* Re: output and digits
  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
  0 siblings, 1 reply; 32+ messages in thread
From: Robert A Duff @ 2005-04-20 13:56 UTC (permalink / raw)


"Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:

> >    type Roman_Digit is ('I','V','X','L','C','D','M');
> >    for Roman_Digit use ('I' => Character'('I')'val,
> >                         'V' => ...);
> >
> > Then Unchecked_Conversion from Roman_Digit to Character will work.
> > Except that you then need to order the Roman_Digits in the same
> > order as in Character: "... is ('C', 'D', ..., 'X')".
> 
> This works (if you correct it slightly to integer(character'pos('I')) - pos
> gives a universal integer!), but changing the order does not seem nice in a
> language like Ada...

Oops.  Yeah, 'Pos is what you want.  But you don't need the conversion
to Integer.

What you *really* want is:

    subtype Roman_Digit is Character
        restricted to ('I','V','X','L','C','D','M'); -- Not Ada!

or perhaps:

    type Roman_Digit is new Character
        restricted to ('I','V','X','L','C','D','M'); -- Not Ada!

Actually, it makes no sense to do arithmetic on roman numerals.
So if I were doing this, I would have two functions, for converting
integers to/from roman numerals represented as Strings.
You only need roman numerals for I/O.  All internal processing
can be done in integers.

That's how you'd do it an any language.

- Bob



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

* Re: output and digits
  2005-04-20 13:56     ` Robert A Duff
@ 2005-04-20 19:53       ` Staszek Goldstein
  0 siblings, 0 replies; 32+ messages in thread
From: Staszek Goldstein @ 2005-04-20 19:53 UTC (permalink / raw)


Uzytkownik "Robert A Duff" <bobduff@shell01.TheWorld.com> napisal w 
wiadomosci news:wcc1x95361o.fsf@shell01.TheWorld.com...

>> This works (if you correct it slightly to integer(character'pos('I')) - 
>> pos
>> gives a universal integer!), but changing the order does not seem nice in 
>> a
>> language like Ada...
>
> Oops.  Yeah, 'Pos is what you want.  But you don't need the conversion
> to Integer.

You are right, the representation clause accepts *any* integer type, even 
universal integers, nevertheless I had to add
for Roman_Digit'size use 8;

otherwise it complained that the two converted types have different sizes 
and gave no visible output.

> Actually, it makes no sense to do arithmetic on roman numerals.
> So if I were doing this, I would have two functions, for converting
> integers to/from roman numerals represented as Strings.
> You only need roman numerals for I/O.  All internal processing
> can be done in integers.

I totally agree with this point of view. If fact, my roman numerals were 
given as an example only,
in real life I had problems with output of DNA sequences, which is a more 
serious matter.
Nevertheless, I feel quite satisfied now, after learning so many nice 
solutions to the problem...

Staszek 





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

* Re: output of enumeration types
  2005-04-20  0:17           ` Staszek Goldstein
  2005-04-20  9:53             ` Dmitry A. Kazakov
@ 2005-04-20 23:16             ` Stephen Leake
  1 sibling, 0 replies; 32+ messages in thread
From: Stephen Leake @ 2005-04-20 23:16 UTC (permalink / raw)
  To: Staszek Goldstein; +Cc: comp.lang.ada

"Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:

> Uzytkownik "Stephen Leake" <stephen_leake@acm.org> napisal w wiadomosci 
> news:mailman.54.1113954069.24457.comp.lang.ada@ada-france.org...
>> "Staszek Goldstein" <goldstei@math.uni.lodz.pl> writes:
>>
>>> This
>>
>> please quote enough so we can tell what you are refering to.
>
> My letter was an answer to a specific message containing just one idea.

Yes, but I cannot tell which message you were answering. I'm using
Emacs Gnus, which is very good at this sort of thing. The convention
is to quote some of the message, to give context.

-- 
-- Stephe




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

end of thread, other threads:[~2005-04-20 23:16 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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