From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9ce828272f314121 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!usenet-fr.net!news.enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: Stephen Leake Newsgroups: comp.lang.ada Subject: Re: output of enumeration types Date: Mon, 18 Apr 2005 20:07:16 -0400 Organization: Cuivre, Argent, Or Message-ID: References: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: melchior.cuivre.fr.eu.org 1113869257 91651 212.85.156.195 (19 Apr 2005 00:07:37 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 19 Apr 2005 00:07:37 +0000 (UTC) Cc: comp.lang.ada@ada-france.org To: "Staszek Goldstein" Return-Path: In-Reply-To: (Staszek Goldstein's message of "Tue, 19 Apr 2005 01:35:37 +0200") User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:10550 Date: 2005-04-18T20:07:16-04:00 "Staszek Goldstein" 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