next up previous contents index
Next: Conditional StatementsBranching Up: MIDAS Command Language Previous: DO Loops

Local Keywords

 

Because keywords are implemented as a global data structure, different MIDAS procedures can access the same keyword. This useful feature can cause problems, however, if these keywords just serve as local, temporary variables like the DO variables. Consider the procedures below:

!+
! Example 11, MIDAS procedure exa11.prg
!+
WRITE/KEYWORD N/I/1/1 0
DO N = 1 10
@@ test
ENDDO

!+
! MIDAS procedure test.prg
!+
WRITE/KEYWORD N/I/1/1 0
DO N = 1 12
WRITE/KEYWORD INPUTI/I/12/1 N
ENDDO

Executing @@ exa11 will give some unexpected results, since both procedures access the same integer keyword N as a common variable.

Therefore, procedures should use local keywords for DO loops  and internal working storage. Local keywords are defined inside a MIDAS procedure via the command DEFINE/LOCAL. They are only known inside the procedure where they are defined (if the lower_levels_flag is set, they are also defined in all procedures called from this procedure). Local keywords  may have the same name as an existing global keyword (except the system keyword names as stored in MID_MONIT:syskeys.dat) or local keyword of any other procedure, since local keywords are searched before the global ones. The above example will work, if modified as follows:

!+
! Example 12, MIDAS procedure exa12.prg
!+
DEFINE/LOCAL N/I/1/1 0
DO N = 1 10
@@ test
ENDDO

!+
! MIDAS procedure test.prg
!+
DEFINE/LOCAL N/I/1/1 0
DO N = 1 12
WRITE/KEYWORD INPUTI/I/12/1 N
ENDDO

Local keywords are deleted when returning to the next higher level at the end of a procedure.



Pascal Ballester
Fri Mar 24 17:17:52 MET 1995