ICL> X = 1
ICL> PROC FRED
FRED> X = 1.2345
FRED> =X
FRED> END PROC
ICL> FRED
1.2345
ICL> =X
1
ICL>
When we run the procedure FRED we get the value of the variable X in the
procedure. Then typing =X gives the value of X outside the procedure which
has remained unchanged during execution of the procedure. This feature has the
consequence that we can use procedures freely without having to worry about
any possible side effects of the procedure on variables outside it.
The situation is exactly the same as that in FORTRAN where variables in a subroutine are local to the subroutine in which they are used. In FORTRAN the COMMON statement is provided for use in cases where it is required to extend the scope of a variable over more than one routine. ICL does not have a COMMON facility but does provide an alternative mechanism for accessing variables outside their scope using the command VARS and the function VARIABLE.
The command VARS is used to list all the variables of a procedure. It has one parameter, which is the name of the procedure. If the parameter is omitted, then the outer level variables, i.e. those that are not part of any procedure are listed. Thus in the previous example:
ICL> VARS FRED
X REAL 1.23450E+00
ICL> VARS
X INTEGER 1
ICL>
VARIABLE is a function whose result is the value of a given variable in
a given procedure:
ICL> = VARIABLE(FRED,X)
1.234500
ICL>
and thus allows a variable belonging to a procedure to be accessed outside
that procedure.
Note that the variables belonging to a procedure continue to exist after
a procedure finishes execution, and if the procedure is executed a second time,
they will retain their values from the first time through the procedure.
ICL The Interactive Command Language for ADAM