@database "ARx_Instr3.ag" @index ARx_Index/ARx_NdxCont @node MAIN "" @toc ARx_Instr.ag/MAIN @prev ARx_Instr.ag/MAIN @next ARx_Instr.ag/MAIN AN AMIGAGUIDE® TO ARexx Second edition (v2.0) by Robin Evans Note: This is a subsidiary file to ARexxGuide.guide. Use that file as the entry point to this and other parts of the full guide. Copyright © 1993,1994 Robin Evans. All rights reserved. @endnode @node PROCEDURE "ARexxGuide | Instruction Reference (16 of 25) | PROCEDURE" @toc ARx_Instr.ag/MAIN @prev ARx_Instr2.ag/PARSE @next PULL PROCEDURE [ @{" EXPOSE " link EXPOSE} [] [...] ] ; Creates a new symbol table for an @{" internal function " link ARx_Elements3.ag/PROGFUNC}. The optional EXPOSE keyword makes @{" " link ARx_Elements2.ag/VARIABLE} available to the function from the calling environment's symbol table. By default, a @{" subroutine " link ARexxGuide.guide/GLOSSARY 248} has access to all variables defined in the main program. It may retrieve the values of those variables and change them. The PROCEDURE instruction protects variables in the main program by giving the subroutine a new symbol table, as though a new script were being executed. Example: /**/ Var = 'I came on a kind of crossroads' CALL SubR SAY Var >>> From time to time. EXIT SubR: SAY Var >>> I came on a kind <...> Var = 'From time to time.' RETURN /**/ Var = 'I came on a kind of crossroads' CALL SubR SAY Var >>> I came on a kind <...> EXIT SubR: PROCEDURE SAY Var >>> VAR Var = 'From time to time.' RETURN In the first program fragment, [Var] in the subroutine inherits the value assigned to it in the main program and is able to change the assignment and affect the value of [Var] in the main program. In the second fragment, on the other hand, the use of PROCEDURE turns [Var] into what is, essentially, a different variable. It is uninitialized when the subroutine begins. The assignment clause within the subroutine has no effect upon the variable used in the main program. Also see @{" Basic elements: Internal functions " link ARx_Elements3.ag/PROGFUNC} explanation Technique note: @{" WordWrap() user function " link ARx_Tknq.ag/WORDWRAP()} @{" Extract file name from full spec " link ARx_Tknq.ag/FILENAME} Next: PULL | Prev: PARSE | Contents: Instruction ref. @endnode @node EXPOSE "ARexxGuide | Instruction Reference | Procedure (1 of 1) | EXPOSE" @toc PROCEDURE @next PROCEDURE @prev PROCEDURE procedure [ EXPOSE <...> ] The EXPOSE option keyword can be used only in conjunction with the @{" PROCEDURE " link PROCEDURE} instruction. It moderates the effect of PROCEDURE by allowing each listed @{i}@{ui} to be treated as part of the symbol table of both the subroutine and the calling environment. Each listed @{i}@{ui} in the subroutine will be treated as it would be in a subroutine that was not modified by the PROCEDURE instruction. Any number of individual variables can be listed after the keyword, but it is often useful to expose a group of variables in one step. That can be done in either of two ways: The first method is to maintain the globals as @{" compound variables " link ARx_Elements2.ag/COMPVAR}. If the @{" stem variable " link ARx_Elements2.ag/COMPVAR2} is used by itself in an EXPOSE list, then all variables formed from that stem will also be exposed. A short stem name like `g!.' is useful in this situation. Example: /* Formatting strings are stored under the g!. stem */ csi='9b'x; g!.slant=csi'3m'; g!.bold=csi'1m'; g!.norm=csi'0m' /* intervening code */ say PrettyUp('This is the', 'absolute', 'finest.') exit PrettyUp: PROCEDURE EXPOSE g!. Emphasis = g!.slant||arg(2)||g!.norm return g!.bold||arg(1) Emphasis g!.bold||arg(3)||g!.norm Another method suggested by ARexx guru @{" Marvin Weinstein " link ARx_Intro.ag/REF} is store symbols to be used as globals in a string and then expand the string with the @{" interpret " link ARx_Instr.ag/INTERPRET} instruction: Example: /* symbols for color strings are stored in another variable */ csi='9b'x; Black=csi'31m'; White=csi'32m'; Blue=csi'33m' Globals = 'Black White Blue' say PrettyUp('This is the', 'absolute', 'finest.') exit PrettyUp: interpret 'PROCEDURE EXPOSE' Globals return White||arg(1) Blue||arg(2) White||arg(3)||Black @{" Compatibility issues: " link ARx_Intro.ag/COMPATIBILITY} The @{" TRL2 " link ARx_Intro.ag/COMPATIBILITY 26} definition of REXX allows an indirect variable list as an argument to this instruction. If @{i}@{ui} is enclosed in parentheses, the standard will use the value of that variable as the list of variable names to be dropped. It works this way: /* Drop variable A and B */ a=1;b=2;c=3;cl= 'a b'; call exposure exit 0 exposure: procedure expose (cl) say a b c >>> 1 2 C Because this option is not supported in ARexx, such a statement would generate @{" Error 31 " link ARx_Error.ag/ERROR_31}. It can, however, be duplicated less elegantly through use of INTERPRET as shown above. Next, Prev & Contents: PROCEDURE @endnode @node PULL "ARexxGuide | Instruction Reference (17 of 25) | PULL" @toc ARx_Instr.ag/MAIN @prev PROCEDURE PULL