comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Problems with visibility of implicit function...
Date: 1996/06/19
Date: 1996-06-19T00:00:00+00:00	[thread overview]
Message-ID: <4q94h4$i37@watnews1.watson.ibm.com> (raw)
In-Reply-To: 4q67nn$sp5@goanna.cs.rmit.EDU.AU


In article <4q67nn$sp5@goanna.cs.rmit.EDU.AU>, Dale Stanbrough
<dale@goanna.cs.rmit.EDU.AU> writes: 

|> I've got some problems calling an implicity declared function
|> which is hidden by an explicity declared one. I've tried
|> renaming, only to end up with infinite recursion. Is the
|> implicity declared function "hidden from all visibility"?
|>
|> --------------------------------------------
|> package lists is
|>      type list is private;
|>
|>      function full(item:list) return boolean;
|> private
|>      ...
|> end lists;
|>
|> with lists;
|> package stacks is
|>      type stack is private;
|>
|>      function full(item:stack) return boolean;
|>
|> private
|>      type stack is new lists.list;
|>      -- inherited & implicitly defined full...
|>      -- function full(item:stack) return boolean;
|> end;
|>
|> package body stacks is
|>
|>      function full(item:stack) return boolean is
|>      begin
|>              ...what?
|>              should i just call on lists.full?
|>      end;
|>
|> end stacks;

Yes, this is an annoying phenomenon.  Because the explicit Stack version
of Full is declared in the visible part, the implicit (inherited) version
is "born hidden" at the point of the derived-type declaration in the
private part.  (This has nothing to do with vlisble versus private, but
just with the fact that the explicit declaration occurs first, so that
the implicit declaration is within the scope of the explicit one.)

The most straightforward solution is: 

   package body Stacks is
      function Full (Item: Stack) return Boolean is
      begin
         return Lists.Full ( List(Stack) );
      end Full;
   end Stacks;

Jonas Nygren asked a similar question not too long ago (message
<316E12F2.37BC@ehs.ericsson.se>), and I suggested the following solution,
which is more intricate but should have no run-time overhead: 

   with Lists;
   package Stacks is
      type Stack is private;
      function Full (Item: Stack) return Boolean;
   private
      package Inner is
         type Parent_Of_Stack is new Lists.List;
         function Parent_Of_Full (Item: Parent_Of_Stack) return Boolean
            renames Full;
      end Inner;
      type Stack is new Inner.Parent_Of_Stack;
      function Full (Item: Stack) return Boolean renames Parent_Of_Full;
         -- Renames
         --    function Parent_Of_Full(Item: Stack) return Boolean;
         -- inherited from  Inner.Parent_Of_Stack and implicitly
         -- declared just after the full declaration for Stack.
   end Stacks;

The trick is to impose an intermediate derived type in which the function
to be inherited is known by a different name, and is thus not hidden by
the declaration of Full in the visible part of Stacks.

--
Norman H. Cohen    ncohen@watson.ibm.com




  parent reply	other threads:[~1996-06-19  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-18  0:00 Problems with visibility of implicit function Dale Stanbrough
1996-06-18  0:00 ` Tucker Taft
1996-06-18  0:00   ` progers
1996-06-19  0:00     ` Robert A Duff
1996-06-19  0:00 ` Norman H. Cohen [this message]
1996-06-19  0:00 ` Chris Warack <sys mgr>
replies disabled

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