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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7816de9c00c8d02a X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Simpler question, create instance of unknown tag Date: 1996/03/18 Message-ID: #1/1 X-Deja-AN: 143042989 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: houdini.camb.inmet.com references: organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-03-18T00:00:00+00:00 List-Id: Robert Dewar (dewar@cs.nyu.edu) wrote: : Scott asked: : " Can one use an Ada.Tags.Tag value (call it a meta-type) : and dynamically use it to create a concrete object : where the new object'Tag = this_tag_value : The compilers definitely can do this (for the Input implementation) : but can us mortals do it?" : No, there is no way to do it, and I have found several times that this : is a minor irritation. For the most part, GNAT translates the stream : attributes into legitimate lower level Ada, but it can't do that for : Input (see GNAT sources for details on the very interesting "kludge" : needed to implement this feature). : It's hard to think of a nice syntax for adding this to the language? You can actually do this in our Ada/Java system (aka "AppletMagic(tm)"). Ada.Tags.Tag is underneath the same type as java.lang.Class; that is a tag corresponds to a "class object." The operation "newInstance" takes a class object and returns an "Object" of the corresponding class, having allocated it on the heap and initialized it via the "default" (parameterless) constructor. You can then use unchecked conversion (which is checked by the Java VM ;-) to convert the result to some more useful Ada type (probably the root type of some type hierarchy). This only works usefully if the type has a meaningful default constructor, which in Ada/Java means the type must have no discriminants and be of a "limited" type. This is of course totally nonportable, but it provides an environment for experimenting with this capability to see how it might be useful, and how it might be made available in "standard" Ada. Having a generic child of Ada.Tags might be one appropriate way to accomplish this, to bundle together the call on newInstance and the (checked) conversion to the appropriate Ada type. -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Cambridge, MA USA