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.3 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a1a88c4d509f6381 X-Google-Attributes: gid103376,public From: czgrr Subject: Re: scope and/or parameters (beginner) Date: 1999/04/08 Message-ID: <7ei04q$o$1@nnrp1.dejanews.com>#1/1 X-Deja-AN: 463975673 References: <37064309.889106243@news.dsuper.net> <37084459.8616007@rocketmail.com> <370b0c99.1137352783@news.dsuper.net> X-Http-Proxy: 1.0 x6.dejanews.com:80 (Squid/1.1.22) for client 193.192.234.4 Organization: Deja News - The Leader in Internet Discussion X-Article-Creation-Date: Thu Apr 08 10:24:29 1999 GMT Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows NT) Date: 1999-04-08T00:00:00+00:00 List-Id: 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