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,LOTS_OF_MONEY 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-07 11:35:27 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: point by point advantages of Ada Date: Tue, 7 Jan 2003 13:34:35 -0600 Organization: Posted via Supernews, http://www.supernews.com Message-ID: 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> X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:32696 Date: 2003-01-07T13:34:35-06:00 List-Id: James S. Rogers wrote in message ... >"David Thompson" wrote in message >news:24oS9.30853$p_6.2594702@bgtnsc04-news.ops.worldnet.att.net... >> Ada uses return type to resolve overloading (at compile time), but >> not to dispatch (possibly at run time). (C++ and Java do neither.) > >Quoting from "Ada as a Second Language" by Cohen: >"If a primitive function of a type T has a result of type T, but no parameters >of type T or access T, a call on the function can be either nondispatching or >dispatching depending on the context." > >This is clearly more than simple overload resolution. But it's not quite dispatching on the tag of the result (which you can't know). But it is dispatching on the tag of result that you need. Here is a quick example of it: type T is tagged ... function Build_It (I : in Integer) return T; --(1) procedure Copy (Target : out T; Source : in T); type NT is new T ... function Build_It (I : in Integer) return NT; --(2) type NNT is new T ... function Build_It (I : in Integer) return NNT; --(3) procedure Do_Something (Obj : in out T'Class) is begin ... Copy (Obj, Build_It(10)); -- Here is the dispatching on result type. ... end Do_Something; This call to Copy is dispatching. The first parameter is dynamically tagged, and the second is tag-indeterminate. Since Build_It has no dispatching parameters, it takes the tag to dispatch on from the enclosing call of Copy (RM 3.9.2(18)). That means that if the tag of Obj is T, then Build_It (1) is called, if Obj is NT, then Build_It (2) is called, and so on. This is convinient for constructor functions, because it means that the right one will automatically be called in a dispatching context. It also means that the tag check (which insures that both operands have the correct tag) can't fail for this call, so Constraint_Error can't be raised by this call. OTOH, I've never actually used this capability in practice. Randy Brukardt.