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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!news4.google.com!news.glorb.com!newscon02.news.prodigy.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: output of enumeration types Date: 18 Apr 2005 21:54:37 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1113875677 17486 192.74.137.71 (19 Apr 2005 01:54:37 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 19 Apr 2005 01:54:37 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:10556 Date: 2005-04-18T21:54:37-04:00 List-Id: "Staszek Goldstein" 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