comp.lang.ada
 help / color / mirror / Atom feed
From: "Norman H. Cohen" <ncohen@watson.ibm.com>
Subject: Re: types in procedure arguments
Date: 1996/10/01
Date: 1996-10-01T00:00:00+00:00	[thread overview]
Message-ID: <3251278D.516D@watson.ibm.com> (raw)
In-Reply-To: 52piii$8n7@noc2.drexel.edu


Chris Papademetrious wrote:

> with Tst_Double_List; -- double linked-list package
> with Tst_Vectors;
> 
> package Tst_Best_Congruence is
> 
>    package Vec_List is new Tst_Double_List(ELEMENT_OBJECT =>
> Tst_Vectors.Vector);
> 
>    procedure Best_Congruence
>    (
>       List: in out Vec_List.LIST_ID
>    );
> 
> end Tst_Best_Congruence;
> generic
>    type ELEMENT_OBJECT is private;
> package Tst_Double_List is
>    type LIST_ID is limited private;
> private
>    type LIST_ID is 
>       record
>          Item1, Item2, Item3: ELEMENT_OBJECT;
>       end record;
> end Tst_Double_List;
> package Tst_Vectors is
>   type Vector is array (0..9) of Float;
> end Tst_Vectors;
> with Tst_Double_List; -- double linked-list package
> with Tst_Best_Congruence;
> with Tst_Vectors;
> 
> procedure Tst is
> 
>   package Vec_List is new Tst_Double_List(ELEMENT_OBJECT =>
> Tst_Vectors.Vector);
> 
>   L: Vec_List.LIST_ID;
> 
> begin
> 
>   Tst_Best_Congruence.Best_Congruence(L);
> 
> end Tst;
> package body Tst_Best_Congruence is
> 
>   procedure Best_Congruence
>   (
>      List: in Point_List.LIST_ID
>   ) is
>   begin
>     List := List;
>   end Best_Congruence;
> 
> end Tst_Best_Congruence;

This is what I thought the problem was.  As you noted in another post,
each instantiation 

   package Instance is new Tst_Double_List(T);

creates a NEW type Instance.List_ID, even if the generic actual
parameter T is the same in both cases and even if the instances
(declared in different declarative regions) have the same name.  You
have created one package named Vec_List nested inside the package
Tst_Best_Congruence and a completely distinct package named Vec_List
nested inside the procedure Tst.  Each of these packages provides a
distinct (although structurally identical) type named List_ID.  

(Perhaps you have experience with C++ templates, instances of which are
uniquely identified by the template name and the template arguments. 
Ada generic templates do not work that way.  An instance of an Ada
generic template comes into existence only as the result of an explicit
generic instantiation, and it is possible to create several distinct
instances with the same generic actual parameters.)

Your solution, as I sketched in my previous note, is to declare ONE
instance of Tst_Double_List, in a compilation unit consisting only of
the generic instantiation:

   with Tst_Double_List, Tst_Vectors;
   package Vec_List is 
      new Tst_Double_List(ELEMENT_OBJECT => Tst_Vectors.Vector);

This is, in effect, the declaration of a separately compiled package
named Vec_List.  Now you can write

   with Vec_List;
   package Tst_Best_Congruence is
      procedure Best_Congruence (List: in out Vec_List.List_ID);
   end Tst_Best_Congruence;

and

   with Vec_List, Tst_Best_Congruence;
   procedure Tst is
      L: Vec_List.List_ID;
   begin
      Tst_Best_Congruence.Best_Congruence(L);
   end Tst;

The with clauses for Vec_List on Tst_Best_Congruence and Tst now
reference the SAME instance of Tst_Double_List.

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




  reply	other threads:[~1996-10-01  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-09-23  0:00 types in procedure arguments Chris Papademetrious
1996-09-25  0:00 ` Stephen Leake
1996-09-28  0:00 ` Chris Papademetrious
1996-09-28  0:00 ` Chris Papademetrious
1996-09-30  0:00 ` Chris Papademetrious
1996-10-01  0:00   ` Norman H. Cohen [this message]
1996-10-01  0:00   ` Robert A Duff
1996-10-01  0:00   ` Stephen Leake
1996-10-01  0:00   ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1996-09-28  0:00 Robert Dewar
1996-09-30  0:00 ` Chris Papademetrious
1996-09-30  0:00   ` Norman H. Cohen
1996-09-30  0:00   ` Stephen Leake
replies disabled

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