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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8623fab5750cd6aa X-Google-Attributes: gid103376,public Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!gnilink.net!nwrdny01.gnilink.net.POSTED!0f19ed38!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: <40b9c99e$0$268$edfadb0f@dread16.news.tele.dk> <1086715817.122983@master.nyc.kbcfp.com> <1086733411.736049@master.nyc.kbcfp.com> <40C85035.4020706@noplace.com> <40C9EC3B.60304@noplace.com> <40CD90A4.8030005@noplace.com> <40CEDCB5.9000509@noplace.com> <1087325485.307616@master.nyc.kbcfp.com> <1087488758.881520@master.nyc.kbcfp.com> Subject: Re: Enum'Image (Was: Improving Ada's image) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Message-ID: Date: Wed, 23 Jun 2004 16:04:04 GMT NNTP-Posting-Host: 141.154.58.140 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny01.gnilink.net 1088006644 141.154.58.140 (Wed, 23 Jun 2004 12:04:04 EDT) NNTP-Posting-Date: Wed, 23 Jun 2004 12:04:04 EDT Xref: g2news1.google.com comp.lang.ada:1813 Date: 2004-06-23T16:04:04+00:00 List-Id: "Jacob Sparre Andersen" wrote in message news:pl4qp57wtw.fsf_-_@sparre.crs4.it... > That would probably be the best way to do it. It would keep old > programs working, and it seems like a logical Ada-like way of doing > things. > > type Colours is (Red, Green, Blue); > for Red'Image use "R"; > for Green'Image use "G"; > for Blue'Image use "B"; As an alternative, how about the ability to write your own Image function? If I had the task of inventing Ada over again, I would make cut a lot of the attribute functions (such as 'Max, 'Image, 'Value, etc.) and replace them with inherited subprograms that the programmer would be free to override. In other words, if you declare type Colours is (Red, Green, Blue); then this type would inherit the function function Image( X : in Colours ) return String; and this inherited function would return one of the strings "RED", "GREEN", or "BLUE". If this is unacceptable, you could override this version of Image by writing your own version, and declaring it in the same scope as the type definition: type Colours is (Red, Green, Blue); function Image( X : in Colours ) return String; If Image worked this way, instead of being an attribute, it would be completely customizable. We can return results in any letter case: upper, lower, mixed, or custom. The result of Image can contain spaces when this aids readability. Image can be internationalized, e.g. we can have Image(Red) return "Red" if the locale is U.S., but return "Rouge" if the locale is France. The possibilities would be endless.