comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@acm.org>
To: "Staszek Goldstein" <goldstei@math.uni.lodz.pl>
Cc: comp.lang.ada@ada-france.org
Subject: Re: output of enumeration types
Date: Mon, 18 Apr 2005 20:07:16 -0400
Date: 2005-04-18T20:07:16-04:00	[thread overview]
Message-ID: <mailman.46.1113869255.24457.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <d41g8c$a16$1@achot.icm.edu.pl> (Staszek Goldstein's message of "Tue, 19 Apr 2005 01:35:37 +0200")

"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




  reply	other threads:[~2005-04-19  0:07 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 [this message]
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
replies disabled

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