× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



James Lampert wrote:
Quick question:

In ILE RPG, is the scope of procedure-level variables lexical or dynamic?

I'm thinking dynamic (and my recent recursion experiments suggest that), but I'm not sure.


When you say your recursion experiments suggest dynamic, you're talking about the storage type for the variables (see Joe Pluta's original post in this thread). You probably had variables in automatic storage, which meant you got new storage for each recursion. If you had coded STATIC, you would have seen different results (same variable for all recursions).

RPG uses lexical scope. The only scopes for names in RPG are global and local; RPG doesn't have block scoping or nested procedures. If a name is global and it's local in a procedure, then anywhere within the procedure, the local version of the name is used. Anywhere outside the procedure, the global version of the name is used.

This is true even if the local variable is defined after it is used in the procedure. In the following example, the "IF" statement in procedure myproc uses the local version of X even though it is not defined until after it is used.

D X S 10A inz('global')

P myproc B
C if X = 'global'
* X is not equal to 'global' because this is the local X
...
C move 'local' X 10

(I had never heard of dynamic scope before today. The idea of using a language which supports dynamic scope makes me a bit carsick.)


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.