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,982ed90dd25179ec X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-08 10:08:06 PST Message-ID: <3E1C64ED.7080807@cogeco.ca> From: "Warren W. Gay VE3WWG" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.1) Gecko/20020823 Netscape/7.0 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: point by point advantages of Ada References: <1041186672.615164@ns2-ext.dcu.ie> <8EIP9.19113$p_6.1493222@bgtnsc04-news.ops.worldnet.att.net> <24oS9.30853$p_6.2594702@bgtnsc04-news.ops.worldnet.att.net> <3E1B4C4C.7050205@cogeco.ca> <3E1B7298.6E29EB8B@adaworks.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 08 Jan 2003 12:50:37 -0500 NNTP-Posting-Host: 198.96.47.195 X-Complaints-To: abuse@sympatico.ca X-Trace: news20.bellglobal.com 1042048237 198.96.47.195 (Wed, 08 Jan 2003 12:50:37 EST) NNTP-Posting-Date: Wed, 08 Jan 2003 12:50:37 EST Organization: Bell Sympatico Path: archiver1.google.com!news2.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!torn!webster!nf1.bellglobal.com!nf2.bellglobal.com!news20.bellglobal.com.POSTED!not-for-mail Xref: archiver1.google.com comp.lang.ada:32757 Date: 2003-01-08T12:50:37-05:00 List-Id: 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