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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e5eb8ca5dcea2827 X-Google-Attributes: gid103376,public From: Samuel Mize Subject: Re: Ada OO Mechanism Date: 1999/05/27 Message-ID: <7ik1e5$8bc@news1.newsguy.com>#1/1 X-Deja-AN: 482808454 References: <7i05aq$rgl$1@news.orbitworld.net> <7i17gj$1u1k@news2.newsguy.com> <7icgkg$k4q$1@nnrp1.deja.com> <3749E9EC.2842436A@aasaa.ofe.org> <7id2eo$fag@drn.newsguy.com> <3749FF7D.F17CE16A@aasaa.ofe.org> <374AC676.F7AE0772@lmco.com> <7ieuja$5v9@news1.newsguy.com> Organization: ImagiNet Communications, Ltd. User-Agent: tin/pre-1.4-981002 ("Phobia") (UNIX) (AIX/3-2) Newsgroups: comp.lang.ada Date: 1999-05-27T00:00:00+00:00 List-Id: Hyman Rosen wrote: > Samuel Mize writes: >> -- This dispatches on both parameters, so they have to match >> -- at run-time >> procedure Operation_4 (A: A_Type; B: B_Type); > > (Do you mean B: A_Type ?) > > Thanks, this is the kind of example I meant! This is something that > C++ can't do by itself. When you say "match at runtime" do you mean > that their dynamic types must be the same? Does the code raise an > exception if they happen not to match? Yep. I said elsewhere I'd bone up on this and explain it. Here goes. I haven't been actually using this for a couple of years (dang it), so everybody else backstop me and catch any errors. In a call on a potentially dispatching function or procedure, all the tags of the controlling parameter values have to match, or you get a constraint error at run-time. And, they must be all statically tagged or all dynamically tagged. A value can be statically tagged, dynamically tagged, or tag indeterminate. - It's statically tagged if it is of a specific tagged type. - It's dynamically tagged if it's of a class-wide type. - It's tag indeterminate ONLY if it's a function call, AND its parameters (if any) don't determine its tag. (Such a function call must be able to determine the tag to use for its result from the context of the call.) Note that the tag of a function call depends on the tags of its parameters. It's statically or dynamically tagged, whichever the parameters are. If there are no statically or dynamically tagged parameters, the call is tag indeterminate, and you have to be able to tell from the context of the call what tag to use. Here is a little example code. Given the package: package T_Types is type T1 is tagged null record; procedure Op1 (P1: T1; P2: T1); type T1_Class_Access is access T1'Class; type T1_1 is new T1 with null record; -- implicit op1 declared here type T2 is tagged null record; procedure Op1 (P1: T1'class; P2: T2); end t_types; And the following data items: V1: T1; V1_1: T1_1; V1_Class_Access: T1_Class_Access := new T1; V2: T2; Then we can have the following calls, some of which are illegal at compile time and one of which raises Constraint_Error at run time: --------- -- DISPATCHING TO SUBTYPES OF T1 --------- -- legal -- static call to T1.op1 op1 (V1, V1); -- not legal, tags must match --op1 (V1, V1_1); -- not legal, must both be either static or dynamic tagged --op1 (V1, V1_Class_Access.all); -- legal -- dispatching call to op1 in some descendant of T1 op1 (V1_Class_Access.all, V1_Class_Access.all); -- legal -- both are now dynamically tagged op1 (T1'Class (V1), V1_Class_Access.all); -- legal at compile time, but fails at run time because the -- tags don't match --op1 (T1'Class (V1_1), V1_Class_Access.all); --------- -- DISPATCHING TO SUBTYPES OF T2 --------- -- all legal op1 (V1, V2); op1 (V1_1, V2); op1 (V1_Class_Access.all, V2); I hope you find this of some interest. Best, Sam Mize -- Samuel Mize -- smize@imagin.net (home email) -- Team Ada Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam