From: "Warren W. Gay VE3WWG" <ve3wwg@cogeco.ca>
Subject: Re: point by point advantages of Ada
Date: Wed, 08 Jan 2003 12:50:37 -0500
Date: 2003-01-08T12:50:37-05:00 [thread overview]
Message-ID: <3E1C64ED.7080807@cogeco.ca> (raw)
In-Reply-To: 3E1B7298.6E29EB8B@adaworks.com
Richard Riehle wrote:
> "Warren W. Gay VE3WWG" wrote:
>>I thought that this might work:
>>
>> declare
>> V : T'Class := ...
>> begin
>> ...
>> V := Some_Other_Func; - Dispatching
>> end;
>>
>>But GNAT (at least) reports that this assignment is "ambiguous"
>>and will not compile it. I would have expected that it would
>>resolve it at runtime, knowing the current value of V and its
>>current tag. Is this consistent with the LRM (IANAL)?
>
> I am not sure if you have tried this, but I often create a function
> such as,
>
> function Get ( ... ) return T'Class;
>
> Then, I initialize the declaration with
>
> V : T'Class := Get (... );
>
> where the parameter list might be the name of a data structure,
> a file, or even a simple array along with the next index. This
> works really well in solving a lot of problems with dispatching.
>
> Richard Riehle
Absolutely -- I love this feature. In fact the Booch components
rely on this as well, for the Iterators (I use BC a lot). For
example:
procedure Close_Widget_List(List : in out WPD.List) is
Iter : WPC.Iterator'Class := WPD.New_Iterator(List);
W : Widget_Handle;
begin
while not WPC.Is_Done(Iter) loop
W := WPC.Current_Item(Iter); -- Handle of current widget in list
Close(W); -- Destroy the widget and its children
WPC.Next(Iter); -- Advance to the next widget in the list
end loop;
WPD.Clear(List); -- Empty the list
end Close_Widget_List;
Note the WPC.Iterator'Class type.
I was just trying to see if true runtime dispatching could occur
on the return type. It would seem that in my earlier example,
that the V := Some_Other_Func dispatch is fixed at compile
time, if it is not ambiguous. I suppose that this is the
"safe" thing to do, and probably why it works that way.
But again, I did not try it with AONIX or any other compiler, and
I've not researched the LRM position on this.
--
Warren W. Gay VE3WWG
http://home.cogeco.ca/~ve3wwg
next prev parent reply other threads:[~2003-01-08 17:50 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-26 21:57 point by point advantages of Ada Russ
2002-12-27 10:54 ` Ingo Marks
2002-12-27 21:11 ` Keith Thompson
2002-12-27 21:31 ` Robert A Duff
2002-12-29 18:31 ` Colin Paul Gloster
2002-12-29 20:09 ` James S. Rogers
2003-01-06 23:13 ` David Thompson
2003-01-07 1:35 ` James S. Rogers
2003-01-07 19:34 ` Randy Brukardt
2003-01-07 21:53 ` Warren W. Gay VE3WWG
2003-01-08 0:36 ` Richard Riehle
2003-01-08 17:50 ` Warren W. Gay VE3WWG [this message]
2003-01-08 20:31 ` Randy Brukardt
2003-01-13 16:37 ` Mark Biggar
2002-12-29 21:56 ` Hyman Rosen
2002-12-29 22:30 ` John R. Strohm
2002-12-29 23:16 ` Hyman Rosen
2003-01-02 14:24 ` Wes Groleau
2003-01-03 8:20 ` Hyman Rosen
2003-01-03 14:00 ` Wes Groleau
2003-01-08 20:55 ` Georg Bauhaus
2002-12-29 19:20 ` chris.danx
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox