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.1 required=5.0 tests=BAYES_05,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,28b389d4503cb555 X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: generic package dilemma Date: 1999/11/17 Message-ID: <3832e27f_1@news1.prserv.net>#1/1 X-Deja-AN: 549769054 Content-transfer-encoding: 7bit References: <80u48b$ghr$1@bunyip.cc.uq.edu.au> Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 17 Nov 1999 17:14:39 GMT, 32.101.8.12 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-11-17T00:00:00+00:00 List-Id: In article <80u48b$ghr$1@bunyip.cc.uq.edu.au> , "Riyaz Mansoor" wrote: > the main procedure initialises "gen_pack1" and "gen_pack4" as below > > -- main procedure > with gen_pack1; > with gen_pack4; You should always elaborate packages that you instantiate: pragma Elaborate (Gen_Pack1); pragma Elaborate (Gen_Pack4); > procedure main is > package pack1 is new gen_pack1; use pack1; > package pack4 is new gen_pack4; use pack4; > blah blha > begin > blah > end main; > > ============================================== > "gen_pack1" initialises "gen_pack2" and "gen_pack3" as below. > > -- gen_pack1 > with gen_pack2; > with gen_pack3; > package gen_pack1 is > package pack2 is new gen_pack2; use pack2; > package pack3 is new gen_pack3; use pack3; > blah blah > end gen_pack1; > > > the above works fine (as i see it). main instantiates pack1, and then pack1 > instantiates pack2 & pack3. the main does recieve a valid variable from > pack1 (and therfore pack2 and pack3). > > heres the problem. this variable is now passed int pack4 from the main. > pack4 NEEDS functions and procedures in pack2 and pack3 to manipulate the > variable. at the moment i've set pack4 as below and it does NOT work That's because these are different instantiations of Gen_Pack2 and Gen_Pack3. The solution is to have Gen_Pack4 import the instantiations, instead of making its own: > -- gen_pack4 > with gen_pack2; > with gen_pack3; generic with package Pack2 is new Gen_Pack2 (<>); with package Pack3 is new Gen_Pack3 (<>); > package gen_pack4 is > -- create copy > blah blah > end gen_pack4; > > it gives a type error! Yes, of course it does. Because these are different types! Now, during your instantiation of Gen_Pack4, pass in the instantiations of Gen_Pack2 and Gen_Pack3: procedure main is package pack1 is new gen_pack1; use pack1; package pack4 is new gen_pack4 (Pack1.Pack2, Pack1.Pack3); use pack4; ^^^^^^^^^^^^^^^^^^^^^^^^^^ blah blha begin blah end main; > says that expected type is pack2.(type) but found > type is pack21.(type). same for the other package. > i even tried using the same names (stupid maybe) but to no avail. > how can i get out of this? or is this a major design flaw? Not "major"; just a misunderstanding of what an instantiation means. -- The new standards [for science curricula in Kansas] do not forbid the teaching of evolution, but the subject will no longer be included in statewide tests for evaluating students--a virtual guarantee, given the realities of education, that this central concept of biology will be diluted or eliminated, thus reducing courses to something like chemistry without the periodic table, or American history without Lincoln. Stephen Jay Gould, Time, 23 Aug 1999