> James Lampert wrote:
>> In ILE RPG, is the scope of procedure-level variables lexical or dynamic?

David Gibbs wrote:

Pardon my denseness here ... but what does 'lexical' mean in this context?

I just glanced over the Wikipedia article "Scope (programming", because I was unsure as well.

If I'm following it correctly, you can think of it as compile-time (lexical) vs. run-time (dynamic) determination of scope. I think I have an example of how this could make a difference in RPGLE. James, please correct me if I'm wrong. I'd also be interested to know what your use case is.

<pseudo code>
declare varName (integer)
call procB

procA
declare varName (packed)
call procB

procB
varName = 3

</pseudo code>


If I'm understanding correctly, if the language in question uses lexical scoping then in the example above varName would be treated as an integer in both invocations, because the global scope is, as the Wikipedia article put it, the "nearest enclosing scope".

In a dynamically scoped language, the "mainline" invocation of procB would have varName treated as an integer, but when procA is invoked from procA, varName would be treated as packed. In this case, the scope is determined by the most recent (re)definition of varName.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.