comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: generic package dilemma
Date: 1999/11/17
Date: 1999-11-17T00:00:00+00:00	[thread overview]
Message-ID: <3832e27f_1@news1.prserv.net> (raw)
In-Reply-To: 80u48b$ghr$1@bunyip.cc.uq.edu.au

In article <80u48b$ghr$1@bunyip.cc.uq.edu.au> , "Riyaz Mansoor" 
<s800032@student.uq.edu.au> 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




  reply	other threads:[~1999-11-17  0:00 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-17  0:00 generic package dilemma Riyaz Mansoor
1999-11-17  0:00 ` Matthew Heaney [this message]
1999-11-17  0:00   ` Mats Weber
1999-11-17  0:00     ` Matthew Heaney
1999-11-18  0:00       ` Robert A Duff
1999-11-18  0:00         ` Matthew Heaney
1999-11-18  0:00       ` Mats Weber
1999-11-18  0:00         ` Matthew Heaney
1999-11-19  0:00           ` Mats Weber
1999-11-19  0:00             ` Vladimir Olensky
1999-11-19  0:00             ` Matthew Heaney
1999-11-19  0:00               ` Mats Weber
1999-11-22  0:00                 ` Robert Dewar
1999-11-22  0:00                   ` Mats Weber
1999-11-22  0:00                     ` Bryce Bardin
1999-11-23  0:00                     ` Robert Dewar
1999-11-22  0:00                   ` Mats Weber
1999-11-22  0:00                     ` Robert A Duff
1999-11-23  0:00                       ` Robert Dewar
1999-12-01  0:00                       ` Robert I. Eachus
1999-12-01  0:00                         ` Robert I. Eachus
1999-11-22  0:00                   ` Robert A Duff
1999-11-23  0:00                     ` Robert Dewar
1999-11-29  0:00                       ` Robert A Duff
1999-12-01  0:00                         ` Robert Dewar
1999-12-01  0:00                       ` Robert A Duff
1999-12-02  0:00                         ` Mats Weber
1999-12-03  0:00                           ` Robert Dewar
1999-12-03  0:00                             ` Ted Dennison
1999-12-04  0:00                               ` Robert Dewar
1999-12-03  0:00                             ` Robert A Duff
1999-12-06  0:00                               ` Robert Dewar
1999-11-22  0:00                   ` Larry Kilgallen
1999-11-23  0:00                     ` Robert Dewar
1999-11-19  0:00               ` Robert Dewar
1999-11-19  0:00                 ` Matthew Heaney
1999-11-20  0:00                   ` Mats Weber
1999-11-19  0:00                 ` Robert I. Eachus
1999-11-22  0:00                   ` Robert Dewar
1999-11-22  0:00                     ` Matthew Heaney
1999-11-19  0:00       ` Robert Dewar
1999-11-18  0:00   ` Riyaz Mansoor
1999-11-19  0:00     ` Robert Dewar
1999-11-19  0:00   ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox