comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Simpler question, create instance of unknown tag
Date: 1996/03/18
Date: 1996-03-18T00:00:00+00:00	[thread overview]
Message-ID: <DoH0Hs.Dt4.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: dewar.826948716@schonberg

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




  reply	other threads:[~1996-03-18  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-03-15  0:00 Simpler question, create instance of unknown tag Scott Moody
1996-03-15  0:00 ` Simpler question, create instance of unkno Scott Moody
1996-03-15  0:00 ` Simpler question, create instance of unknown tag Robert Dewar
1996-03-18  0:00   ` Tucker Taft [this message]
     [not found]   ` <4ikbhn$cl6@watnews1.watson.ibm.com>
     [not found]     ` <DoHFu8.E2A@world.std.com>
1996-03-19  0:00       ` Norman H. Cohen
1996-03-19  0:00         ` Robert A Duff
1996-03-26  0:00       ` AdaWorks
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox