comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: Position of "use"
Date: Tue, 8 Jul 2014 12:30:40 -0700 (PDT)
Date: 2014-07-08T12:30:40-07:00	[thread overview]
Message-ID: <89f04209-3cb5-47c5-b69a-a516df2437de@googlegroups.com> (raw)
In-Reply-To: <lp86r0$ssl$1@speranza.aioe.org>

On Friday, July 4, 2014 11:43:46 PM UTC-7, Victor Porton wrote:
> What is the difference between
> 
> with X; use X;
> package Y is
> end Y;
> 
> and
> 
> with X;
> package Y is
>    use X;
> end Y;
> 
> ?

OK, I've looked into it, and there's no difference.  I'm assuming that there may be more code in the specification of Y, but that in the second example, "use X" is the first thing in this specification.  

RM 8.4(6-7) describe the "scope" of a use_clause, which is the portion of code that is affected by the "use".  If it's in the context clause, the scope is the entire declarative region of the package.  If it's inside the declarative region, the scope is the part of the declarative region starting from the "use" and ending at the end of the declarative region; if the "use" clause is the first thing in the region (as in the second example above), that means that the scope is the entire declarative region of the package, same as the first example.  (Note that in both cases, the declarative region will include child packages, if any.  This follows from the rules in RM 8.1.)

The scope doesn't include the context clause itself.  (The context clause is the "with" and "use" statements that occur before the "package/procedure/function" of a top-level library unit, and it may include pragmas.)  RM 10.1.6 says that the visibility rules don't apply to the context clause, and it contains special rules for context clauses.  Nothing in those rules says that "use" makes anything visible in a context clause; therefore, a "use" in a context clause has no effect on any other "with", "use", or "pragma" in the context clause, or in any other context clause (i.e. the context clause on a child package or subunit). 

Therefore, the effect of a "use" that is the first thing in a package specification has the exact same effect as a "use" appearing in the context clause.

                           -- Adam

  parent reply	other threads:[~2014-07-08 19:30 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-05  6:43 Position of "use" Victor Porton
2014-07-05  7:12 ` J-P. Rosen
2014-07-07 16:45   ` Adam Beneschan
2014-07-07 17:08     ` Pascal Obry
2014-07-07 17:40       ` Peter Chapin
2014-07-07 19:17       ` Adam Beneschan
2014-07-08  5:26     ` J-P. Rosen
2014-07-08 15:32       ` Adam Beneschan
2014-07-08 19:30 ` Adam Beneschan [this message]
2014-07-08 22:39   ` Victor Porton
2014-07-09 10:36 ` anon
2014-07-09 15:14   ` Adam Beneschan
2014-07-10  1:27     ` anon
2014-07-10  9:50       ` AdaMagica
2014-07-10 13:10         ` J-P. Rosen
2014-07-10 15:57           ` Adam Beneschan
2014-07-10 17:47             ` Tero Koskinen
2014-07-10 19:15           ` Jeffrey Carter
2014-07-15  5:56         ` anon
2014-07-15  7:36           ` Georg Bauhaus
2014-07-15 17:01             ` Simon Wright
2014-07-15 17:23               ` Jeffrey Carter
2014-07-15 19:44                 ` Simon Wright
2014-07-15 17:47               ` G.B.
2014-07-15 17:51               ` Adam Beneschan
2014-07-15 20:04                 ` Simon Wright
2014-07-16  7:19                 ` anon
2014-07-10 15:54       ` Adam Beneschan
replies disabled

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