PROCEDURE PROCEDURE EXPOSE var1 [var2 ...] PROCEDURE HIDE var1 [var2 ...] (LOCAL) The PROCEDURE command is used in an internal function or procedure to hide the caller's variables. The PROCEDURE command on its own hides all the caller's variables and makes sure that on return all the current function's variables are erased. On return from a function containing this instruction, the caller's old variables are reinstated when the current function's have been deleted. The PROCEDURE EXPOSE varlist command is like the form with no arguments except that all the named variables are left visible. These variables will all remain when the RETURN statement deletes all the other variables from the current function. If any of the named variables are not defined, then they will remain undefined until they are assigned a value. This value will then be carried back to the calling procedure. It is not an error to specify a symbol more than once; this will have the same effect as specifying it just once. Simple symbols, stems or compound symbols may be exposed. If a stem is named, then all possible compound symbols starting with that stem will be exposed. BUG: It is not possible to expose a stem and one of its compound symbols at the same time. If a stem is named and one of its compound symbols appears later, then the compound symbol has in effect already been exposed and so the expected results will occur. However, if a stem appears after one of its compound variables, the stem will be ignored without a warning. Any symbol(s) in the list following PROCEDURE EXPOSE may be enclosed in parentheses. In such cases the value of the symbol is used as a list of extra symbols to expose. For example, if the assignment: list = "var1 var2 stem. misc.3" occurred in the calling program, then the instruction: procedure expose test1 (list) test2 will expose the following symbols (in this order): test1 list var1 var2 stem. misc.3 test2 Notice that the symbol inside the parentheses is itself exposed before its value is obtained. LOCAL: The PROCEDURE HIDE varlist command hides only the named variables, leaving the rest visible. On return the hidden variables are deleted, leaving all the others. The action of PROCEDURE HIDE list is identical to that of PROCEDURE EXPOSE . (in fact what happens is that all existing symbols are exposed and then the named symbols are deleted from the new variable table. This command is therefore quite inefficient and should be used sparingly). The PROCEDURE HIDE statement may not hide individual compound variables. Only stems and simple symbols should be specified, otherwise a syntax error will result. NOTE: This means that variables which are undefined when the PROCEDURE HIDE statement is executed will be deleted on return from the current function. However, if new compound variables are defined having a stem in common with some compound variables which already exist, then the new compound variables will not be deleted on return. NOTE: As in standard REXX, the order in which the symbols are named can have an effect. For example, if i=5 then procedure expose i a.i will expose i and the compound symbol a.5, but procedure expose a.i i will expose the compound symbol a.I and i. This is because the names are processed from left to right, and in the latter case the symbol i is not visible when the name a.i is encountered. The PROCEDURE command will almost invariably be at the beginning of a function or procedure. It may be used in the middle rather than at the beginning, but this is not recommended. In fact the ANSI standard states that PROCEDURE must be the first instruction of a subroutine, if it is present. In any case, an error will result if it is used within an INTERPRET, or a DO, or some other control structure. LOCAL: If OPTIONS 'EXPOSE' (qv) is in effect then the PROCEDURE instruction will be allowed at the start of a program which is called as an external subroutine or function. This allows variables from the caller (which would normally be hidden) to be exposed. The instruction does not have to be the first in the program but it must not be placed inside any control structure (so it could, for example, be preceded by an OPTIONS 'EXPOSE' instruction). Example: an improved version of the above factorial program parse arg x say x"!="fact(x) exit fact: procedure /* now we get a different p each time */ parse arg p if p<3 then return p return fact(p-1) * p NOTE: The special variable SIGL must be explicitly exposed if its current value is needed within the procedure. It is set by the CALL instruction or the function call before any PROCEDURE instruction is encountered.