comp.lang.ada
 help / color / mirror / Atom feed
From: ashwath30jul77@gmail.com
Subject: Re: Procedure defined in package body accessed by separate procedure
Date: Thu, 13 Feb 2014 22:30:06 -0800 (PST)
Date: 2014-02-13T22:30:06-08:00	[thread overview]
Message-ID: <a6cdd451-c33e-4189-863d-02623aaec1d7@googlegroups.com> (raw)
In-Reply-To: <b5cf2120-1951-4f39-a84d-444bbe47b660@googlegroups.com>

On Thursday, February 13, 2014 10:24:53 PM UTC+5:30, adambe...@gmail.com wrote:
> On Thursday, February 13, 2014 5:58:33 AM UTC-8, G.B. wrote:
> 
>  
> 
> > > package body Greetings is 
> 
> > >     procedure Hello is separate; 
> 
> > >     procedure Goodbye is separate; 
> 
> > >     procedure proc_body is
> 
> > >     begin
> 
> > >        put_line("body");
> 
> > >     end;
> 
> > > end Greetings;
> 
> 
> 
> > > Greetings-Hello.ada:
> 
> > > ================================
> 
> > > with text_io;
> 
> > > use Text_IO;
> 
> > > separate (Greetings)
> 
> > > procedure Hello is
> 
> > > begin
> 
> > >     put_line("Hello");
> 
> > >     Greetings.proc_body;--Compiler error here. Says proc_body is not declared in Greetings
> 
> > > end;
> 
> > 
> 
> > Linearity of reading seems at work here: proc_body, in body
> 
> > Greetings, appears after the line that says "Hello is
> 
> > separate". Therefore, when that line is "evaluated", there
> 
> > is no procedure proc_body (yet).
> 
> 
> 
> Yes, that's the reason.  The RM says (10.1.3(17)):
> 
> 
> 
> "Visibility within a subunit is the visibility that would be obtained at the place of the corresponding body_stub (within the parent body) if the context_clause of the subunit were appended to that of the parent body."
> 
> 
> 
> So that means that the things that are visible to Hello's separate body are the same things that would be visible at the place the "procedure Hello is separate" (the body stub) appeared.  If there were a *new* "with" or "use" clause on the separate body, that would make other things visible as well.  In this case, since there is already "with Text_IO; use Text_IO;" on the body of Greetings, the WITH and USE on the body of Hello doesn't make anything else visible.  (In fact, they're redundant and could be removed.  My personal preference is to include redundant WITH's and USE's anyway, so that you don't have to flip between a bunch of source files to figure out what WITH's and USE's are in effect.)  But anyway, if you wrote all of Hello inline in the body of Greetings, instead of making it separate, you'd get the same error on proc_body; therefore, the same error occurs in the separate body, since the same identifiers are visible.
> 
> 
> 
>                                 -- Adam

Thanks for response Adam.
Is this compiler specific?It seems to compile when Tartan compiler is used :S


  reply	other threads:[~2014-02-14  6:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-13 12:15 Procedure defined in package body accessed by separate procedure ashwath30jul77
2014-02-13 13:58 ` G.B.
2014-02-13 16:54   ` adambeneschan
2014-02-14  6:30     ` ashwath30jul77 [this message]
2014-02-14  9:22       ` Simon Wright
2014-02-13 16:32 ` Dirk Heinrichs
2014-02-13 16:43   ` adambeneschan
2014-02-13 16:57     ` Dirk Heinrichs
2014-02-13 16:59       ` Dirk Heinrichs
replies disabled

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