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!news1.google.com!news.glorb.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!gnilink.net!nwrdny02.gnilink.net.POSTED!0f19ed38!not-for-mail From: "Frank J. Lhota" Newsgroups: comp.lang.ada References: <40b9c99e$0$268$edfadb0f@dread16.news.tele.dk> <1086733411.736049@master.nyc.kbcfp.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 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: Fri, 25 Jun 2004 15:55:55 GMT NNTP-Posting-Host: 151.203.203.234 X-Complaints-To: abuse@verizon.net X-Trace: nwrdny02.gnilink.net 1088178955 151.203.203.234 (Fri, 25 Jun 2004 11:55:55 EDT) NNTP-Posting-Date: Fri, 25 Jun 2004 11:55:55 EDT Xref: g2news1.google.com comp.lang.ada:1890 Date: 2004-06-25T15:55:55+00:00 List-Id: "Jacob Sparre Andersen" wrote in message news:plhdt05wkw.fsf_-_@sparre.crs4.it... > Frank J. Lhota wrote: > > > As an alternative, how about the ability to write your own Image > > function? > > Definitely usable, but I would worry about: > > 1) if my implementation was as efficient as the compiler supplied one Possibly not, but presumably you would not write your own Image function unless you desired something different from the compiler-supplied Image funciton. > 2) 'Image and 'Value being each other's inverse This is similar to the situation with user-defined "+" and "-" operators; you would also want them to be inverses, in that most people would expect that ( A + B ) - B = A There is no way, however, for the compiler to force user-defined "+" and "-" to be inverses of each other, so that responsibility falls to the programmer. The same could be said of user-defined Image and Value functions. Yes, they should be inverses, but that is left up to the programmer. > > 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. > > I have had similar thoughts occasionally, but I am afraid there are > some sensible reasons that it isn't already like that? Enumeration literals can be overloaded, so I have heard the argument that attributes are needed to resolve overloading. For example, if we have the types type Name_Of_Nutrient is ( Vitamin_A, Vitamin_B, ... Calcium, Iron, ... ); type Name_Of_Appliance is ( Blender, Microwave, Iron, ... ); then if we have the function call Image( Iron ) is it referring to the Name_Of_Nutirent Iron or the Name_Of_Appliance Iron? This problem goes away if the Image function is an attribute, for then we would write Name_Of_Nutrient'Image( Iron ) making it clear what the type of Iron we are taking about. This is one way to resolve the ambiguity. Another way would be to use qualified expressions. If Image was overloaded for these two enumeration types, we could also clarify this function call by writing: Image ( Name_Of_Nutrient'( Iron ) ) > Jacob > -- > "Any newsgroup where software developers hang out is > an Emacs newsgroup."