Dynamic scoping or lexical scoping?

What use Natural language:

Dynamic scoping or lexical scoping?

Thanks for the information.

For the most part, Natural is restricted to lexical scoping. In other words, if I define a variable #VAR in the local data area of a program, it is the same #VAR regardless of where I use it in the program.

There is one part of Natural which, depending on your interpretation of it, offers dynamic scoping.

Suppose I have a “driver program”

INPUT +FILE (A32) +SEARCH (A32) +DISPLAY (A50)
RUN ‘REPORT01’
END

Now, here is the program REPORT01:

FIND &FILE
WITH &SEARCH
DISPLAY &DISPLAY
LOOP
END

I have deliberately written both programs in Report Mode, rather than Structured Mode since it makes the code simpler and we can concentrate on dynamic scoping rather than syntax.

Suppose, when the user sees the INPUT screen, they enter EMPLOYEES for +FILE, NAME = GARCIA for +SEARCH, and FIRST-NAME CITY for +DISPLAY.

In the program REPORT01 (note it is RUN, not FETCH’ed) the compiler substitutes the value of +FILE for the text &FILE, the value of NAME = GARCIA for &SEARCH and the value of FIRST-NAME CITY for &DISPLAY. After compilation, Natural now executes the resultant object code.

This is “sort of” dynamic scoping. Why do I say “sort of”? Technically, what I like to call “ampersand variables” are not really variables. They are “text” which gets replaced by the compiler.

However, if I use &DISPLAY in multiple places in REPORT01, it is the same value for a given execution of REPORT01. Some people would say, therefore, that this is not dynamic scoping. It really depends on how you interpret the term “dynamic scoping”.