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.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a45c7f0a721c2c35 X-Google-Attributes: gid103376,public From: ncohen@watson.ibm.com (Norman H. Cohen) Subject: Re: Problems with visibility of implicit function... Date: 1996/06/19 Message-ID: <4q94h4$i37@watnews1.watson.ibm.com>#1/1 X-Deja-AN: 161027340 distribution: world references: <4q67nn$sp5@goanna.cs.rmit.EDU.AU> organization: IBM T.J. Watson Research Center reply-to: ncohen@watson.ibm.com newsgroups: comp.lang.ada Date: 1996-06-19T00:00:00+00:00 List-Id: In article <4q67nn$sp5@goanna.cs.rmit.EDU.AU>, Dale Stanbrough 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