From: czgrr <czgrr@my-dejanews.com>
Subject: Re: scope and/or parameters (beginner)
Date: 1999/04/08
Date: 1999-04-08T00:00:00+00:00 [thread overview]
Message-ID: <7ei04q$o$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 370b0c99.1137352783@news.dsuper.net
In article <370b0c99.1137352783@news.dsuper.net>,
fluffy_doo@dsuper.net wrote:
> On Mon, 05 Apr 1999 05:04:25 +0000, Corey Ashford
[snip]
> This exercise, in part learning to use "named" instead of "positional"
> association, has allowed me to realize the following, I think :
>
> The fact that a sub-program is declared INSIDE another, as
> opposed to OUTSIDE of it, makes no difference from the point of
> view of the compiler. As long as any call to a sub-program is
> made AFTER its declaration it is treated exactly the same way.
>
> TRUE / FALSE ?
The short answer:
For the usage you gave in your original message, yes it makes no difference.
The long answer, part 1:
It does make one important difference. In the same way as local variables are
not accessible outside the routine they are declared in, declaring a routine
inside another limits the scope (accessibility) of that routine.
An example. In the message you originally wrote, you make a call:
> One_Procedure
> (Second_Variable => Var_2, Third_Variable => Var_3);
but if you tried to make the following call *in the same place*:
> Internal_Procedure ( One_Variable => Var_3 );
it would not compile. If you wanted "Internal_Procedure" to be available in
the same places as "One_Procedure", you would have to declare it outside
"One_Procedure".
The long answer, part 2:
This business about calling something after its declaration, strictly, is
true. But in the sense I felt you were talking about it here, you could have
structured your code this way...
> PROCEDURE One_Procedure
> ( Second_Variable : IN The_Type;
> Third_Variable : OUT The_Type ) IS
> -- sub-programs: none ================================
> BEGIN -- One_Procedure
> Internal_Procedure ( One_Variable => (QUESTION) );
> END One_Procedure;
>
> PROCEDURE Internal_Procedure
> ( One_Variable : IN OUT The_Type ) IS
> BEGIN
> One_Variable := One_Variable + A_Constant;
> END Internal_Procedure;
and still have been able to get this to compile. What you do is to put a
declaration for "Internal_Procedure" before that for "One_Procedure", of this
form:
> PROCEDURE Internal_Procedure
> ( One_Variable : IN OUT The_Type ) ; -- NOTE the semi-colon
Then you can call "Internal_Procedure" at any point after this, irrespective
of where the actual code for it lies.
Of course, if you have written specs and bodies, this is exactly the same as a
declaration in the spec - you can think of a spec as coming "before" anything
in the body, and so you can call anything in a package's spec from anywhere
within that package.
Phew! Some more things to play with, eh?
HTH, czgrr.
--
My opinions, etc, are not necessarily those of my employer.
They might not even be right.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
next prev parent reply other threads:[~1999-04-08 0:00 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-02 0:00 scope and/or parameters (beginner) fluffy_pink
1999-04-03 0:00 ` Matthew Heaney
1999-04-05 0:00 ` Corey Ashford
1999-04-05 0:00 ` fluffy_doo
1999-04-06 0:00 ` Matthew Heaney
1999-04-08 0:00 ` czgrr [this message]
1999-04-10 0:00 ` fluffy_puff
1999-04-12 0:00 ` dennison
1999-04-13 0:00 ` Robert Dewar
1999-04-13 0:00 ` czgrr
1999-04-13 0:00 ` Robert Dewar
1999-04-14 0:00 ` czgrr
1999-04-14 0:00 ` Robert Dewar
1999-04-15 0:00 ` czgrr
1999-04-15 0:00 ` Robert Dewar
1999-04-14 0:00 ` dennison
1999-04-13 0:00 ` Robert A Duff
1999-04-14 0:00 ` Robert Dewar
1999-04-14 0:00 ` Hyman Rosen
1999-04-14 0:00 ` dennison
1999-04-14 0:00 ` Hyman Rosen
1999-04-14 0:00 ` dennison
1999-04-14 0:00 ` Hyman Rosen
1999-04-15 0:00 ` dennison
1999-04-15 0:00 ` Robert Dewar
1999-04-15 0:00 ` Hyman Rosen
1999-04-15 0:00 ` dennison
1999-04-15 0:00 ` Robert Dewar
1999-04-15 0:00 ` Hyman Rosen
1999-04-15 0:00 ` Robert Dewar
1999-04-15 0:00 ` Hyman Rosen
1999-04-16 0:00 ` Rakesh Malhotra
1999-04-15 0:00 ` fluffy_dong
1999-04-15 0:00 ` Robert Dewar
1999-04-15 0:00 ` dennison
1999-04-15 0:00 ` fluffy_dong
1999-04-16 0:00 ` Robert Dewar
1999-04-16 0:00 ` Fraser Wilson
1999-04-16 0:00 ` Gautier.DeMontmollin
1999-04-20 0:00 ` Nick Roberts
1999-04-21 0:00 ` fraser
1999-04-22 0:00 ` Robert A Duff
1999-04-22 0:00 ` Larry Kilgallen
1999-04-16 0:00 ` Samuel Mize
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox