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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,be30d7bb9651853b X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-12-09 17:56:11 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!gatech!newsxfer.itd.umich.edu!zip.eecs.umich.edu!panix!cmcl2!thecourier.cims.nyu.edu!thecourier.cims.nyu.edu!nobody From: comar@cs.nyu.edu (Cyrille Comar) Newsgroups: comp.lang.ada Subject: Re: Ada 90 inheritance request? Date: 9 Dec 1994 12:26:13 -0500 Organization: Courant Institute of Mathematical Sciences Message-ID: <3ca3vl$n14@lang8.cs.nyu.edu> References: NNTP-Posting-Host: lang8.cs.nyu.edu Date: 1994-12-09T12:26:13-05:00 List-Id: stt@spock.camb.inmet.com (Tucker Taft) writes: : : Here is the note on multiple inheritance in Ada 9X. : -Tucker Taft Thank's Tuck for your very instructive note. I love this kind of post where I fill like learning something rather than listening to someone complains. By the way, I have an intersting challenge for our Ada9x experts. Here is a problem that would have an obvious solution with Multiple Inheritance, I would like to see how it can be solved cleanly in 9x. The problem is not abstract, this is something that everybody will need at some point. PROBLEM: I have defined a hierarchy or tagged types and now I would like specialize one of them to be controlled (i.e. finalizable) with MI, I could write something like: type Ctrl_T is new T, Controlled with null record; -- overriding of Initialize/Adjust/Finalize procedure Initialize (Obj : in out Ctrl_T); procedure Adjust (Obj : in out Ctrl_T); procedure Finalize (Obj : in out Ctrl_T); and it would be the end of it... Beginning of Solution --------------------- Following your suggestions, we could define a generic package: generic type T is tagged private; package Make_it_Controlled is type Ctrl_T is new T with private; procedure Initialize (Obj : in out Ctrl_T); procedure Adjust (Obj : in out Ctrl_T); procedure Finalize (Obj : in out Ctrl_T); private type T_Controller is new Controlled with null record; procedure Initialize (Obj : in out T_Controller); procedure Adjust (Obj : in out T_Controller); procedure Finalize (Obj : in out T_Controller); type Ctrl_T is new T with record Ctrl : T_Controller; end record; end; and then I need to be able to call Initialize on Ctrl_T inside the Initialize of type T_Controller. Each time a variable V of type Ctrl_T is defined the Initialize on V.Ctrl will be called and will itself call Initialize on V. But now I am stuck because there is no way in the body of Initialize on T_Controller to refer to the englobing object.... Argggg Tuck gave another nice trick by using access discriminant that solves partially the problem. We can use it to redefine the controller: type Acc is access all Ctrl_T; type T_Controller (Englobing_Obj : Acc) is new Limited_Controlled with null record; type Ctrl_T is new T with record Ctrl : T_Controller (Ctrl_T'Access); end; and now I can write Initialize procedure Initialize (Obj : in out T_Controller) is begin Initialize (Obj.Englobing_Obj.all); end; And everything would be nice if it was legal... The problem is that the access discriminant requires a LIMITED TYPE and thus Ctrl_T must be limited. So this approach works pretty well if my formal generic parameter is type T is tagged limited private; This package allows any limited tagged type to be specialized as a limited_controlled type (sort of). MY CHALLENGE is : how to do the same thing with non-limited types ? -- ------------------------------------------------------------------------ Cyrille Comar, E-mail: comar@cs.nyu.edu Gnat Project US phone: (212) 998-3489