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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5b3c19b1631bb558 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2000-11-01 19:45:27 PST Path: supernews.google.com!sn-xit-02!sn-xit-03!supernews.com!xfer13.netnews.com!netnews.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3A00E2D0.42440CB0@acm.org> From: Jeff Carter X-Mailer: Mozilla 4.7 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Reflection (was: Re: The best thing/greatest feature summary) References: <39DCB9E3.EAE8F426@ftw.rsc.raytheon.com> <39F9FCCE.D6719C6F@ftw.rsc.raytheon.com> <1c9kvs4uvj4ofd46f7a8vq0pju596iu2gr@4ax.com> <39fed7b6@rsl2.rslnet.net> <39FF1DBD.74184FDC@worldnet.att.net> <39ff792d@rsl2.rslnet.net> <39FF8DE3.EC0055B5@worldnet.att.net> <3A00375E.19433DC0@worldnet.att.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 02 Nov 2000 03:45:24 GMT NNTP-Posting-Host: 158.252.122.133 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 973136724 158.252.122.133 (Wed, 01 Nov 2000 19:45:24 PST) NNTP-Posting-Date: Wed, 01 Nov 2000 19:45:24 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: supernews.google.com comp.lang.ada:1702 Date: 2000-11-02T03:45:24+00:00 List-Id: Ken Garlington wrote: > > This, of course, is the critical difference between your solution and the > Java solution. "Package_Name" may, or may not, be the name of the Ada > package -- its correctness is only enforced by the programmer's diligence > (particularly in the face of changes). The Java method does not depend upon > keeping the same information copied in two places, as in > > package MyPackage is -- [1] > > package R is new Reflect("MyPackage"); -- [2] > > Given that a goal of Ada is to reduce errors due to copying, the argument > that the Ada approach is not as desirable as the Java approach seems like a > valid criticism to me. I've been toying with this: with Ada.Strings.Fixed; with Ada.Tags; with Mixed_Case; use Ada.Strings.Fixed; use Ada.Tags; generic -- Reflection -- null; package Reflection is Unit_Name : constant String; -- The full name of the unit in which this package is instantiated -- (the null string if instantiated at the library level). -- Unit_Name is in strict mixed-case form [1st character and every -- character after -- a dot ('.') or underline ('_') is in upper case, and all other -- characters are in lower case]. private -- Reflection type T is abstract tagged null record; Name : constant String := Expanded_Name (T'Tag); Dot : constant String := "."; Direction : constant Ada.Strings.Direction := Ada.Strings.Backward; Dot_Location : constant Natural := Index (Name (Name'First .. Index (Name, Dot, Direction) - 1), Dot, Direction); -- 1st Index finds dot before type name -- 2nd Index finds dot before instantiation name Unit_Name : constant String := Mixed_Case (Name (Name'First .. Dot_Location - 1) ); -- Trim off type name and instantiation name end Reflection; Mixed_Case is a simple function and is left as an exercise for the reader. This package indicates that this kind of information is available in Ada. We just need an easier way to access it. -- Jeff Carter "Perfidious English mouse-dropping hoarders." Monty Python & the Holy Grail