comp.lang.ada
 help / color / mirror / Atom feed
* Re: Simpler question, create instance of unknown tag
  1996-03-15  0:00 Simpler question, create instance of unknown tag Scott Moody
@ 1996-03-15  0:00 ` Robert Dewar
  1996-03-18  0:00   ` Tucker Taft
       [not found]   ` <4ikbhn$cl6@watnews1.watson.ibm.com>
  1996-03-15  0:00 ` Simpler question, create instance of unkno Scott Moody
  1 sibling, 2 replies; 7+ messages in thread
From: Robert Dewar @ 1996-03-15  0:00 UTC (permalink / raw)


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?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Simpler question, create instance of unkno
  1996-03-15  0:00 Simpler question, create instance of unknown tag Scott Moody
  1996-03-15  0:00 ` Robert Dewar
@ 1996-03-15  0:00 ` Scott Moody
  1 sibling, 0 replies; 7+ messages in thread
From: Scott Moody @ 1996-03-15  0:00 UTC (permalink / raw)


One more quick thing; Looking at the gnat implementation they
do the following:

               --  Read the internal tag (RM 13.13.2(34)) and use it to
               --  initialize a dummy object with the right tag value:

               --    Dnn : root_type;
               --    Dnn._tag := Internal_Tag (String'Input (Strm))

               --  This dummy object is not initialized (other than its tag)
               --  and is used only to provide a controlling argument for the
               --  eventual _Input call.

Unfortunately this is hidden from me..  Am I trying to do something
that is even too dynamic for the new Ada? Without this capability
I cannot overload the 'Class'Input operations without a Case statement..

scott

ps. my return email is getting goofed up by news. It is:
   scott@plato.ds.boeing.com





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Simpler question, create instance of unknown tag
@ 1996-03-15  0:00 Scott Moody
  1996-03-15  0:00 ` Robert Dewar
  1996-03-15  0:00 ` Simpler question, create instance of unkno Scott Moody
  0 siblings, 2 replies; 7+ messages in thread
From: Scott Moody @ 1996-03-15  0:00 UTC (permalink / raw)


My last input question can be boiled down to a simple
question:

  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?

-scott





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Simpler question, create instance of unknown tag
  1996-03-15  0:00 ` Robert Dewar
@ 1996-03-18  0:00   ` Tucker Taft
       [not found]   ` <4ikbhn$cl6@watnews1.watson.ibm.com>
  1 sibling, 0 replies; 7+ messages in thread
From: Tucker Taft @ 1996-03-18  0:00 UTC (permalink / raw)


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




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Simpler question, create instance of unknown tag
       [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
  1 sibling, 1 reply; 7+ messages in thread
From: Norman H. Cohen @ 1996-03-19  0:00 UTC (permalink / raw)


In article <DoHFu8.E2A@world.std.com>, bobduff@world.std.com (Robert A Duff)
writes: 

|> I believe Norm Cohen could write an entire novel using only the reserved
|> words of Ada.  Maybe even just the reserved words of Ada 83.

And with out XOR or REM or ELSIF

Range of task is not at all limited
Begin with entry and end with exit and accept delay

--
Norman H. Cohen    ncohen@watson.ibm.com




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Simpler question, create instance of unknown tag
  1996-03-19  0:00       ` Norman H. Cohen
@ 1996-03-19  0:00         ` Robert A Duff
  0 siblings, 0 replies; 7+ messages in thread
From: Robert A Duff @ 1996-03-19  0:00 UTC (permalink / raw)


In article <4in6bu$klb@watnews1.watson.ibm.com>,
Norman H. Cohen <ncohen@watson.ibm.com> wrote:
>...

:-)




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Simpler question, create instance of unknown tag
       [not found]     ` <DoHFu8.E2A@world.std.com>
  1996-03-19  0:00       ` Norman H. Cohen
@ 1996-03-26  0:00       ` AdaWorks
  1 sibling, 0 replies; 7+ messages in thread
From: AdaWorks @ 1996-03-26  0:00 UTC (permalink / raw)


Robert A Duff (bobduff@world.std.com) wrote:

: Anyway, I like the above idea.  Now tell me how to support this:

:     X: T'Class;

: It would be nice ;-).

  Yeah, Bob. This is one of the first things one encounters in the
  early stages of learning Ada 95.  

  I have been writing, for some programs, something such as:

         function Get return T'Class;

  and then, for the declaration:

         X : T'Class := Get;

  to ensure compilation.

  The next trick is to decide how to implement function Get. This turns
  out to be quite useful for some situations.

  But then, my guess is that you already do this too.
  
  Richard Riehle
-- 

richard@adaworks.com
AdaWorks Software Engineering
Suite 27
2555 Park Boulevard
Palo Alto, CA 94306
(415) 328-1815
FAX  328-1112




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1996-03-26  0:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-15  0:00 Simpler question, create instance of unknown tag Scott Moody
1996-03-15  0:00 ` Robert Dewar
1996-03-18  0:00   ` Tucker Taft
     [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
1996-03-15  0:00 ` Simpler question, create instance of unkno Scott Moody

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