Scope modifiers: Difference between revisions

→‎{{header|REXX}}: add Version 2 with comments on dynamic scope
m (→‎{{header|REXX}}: changed the REXX section header.)
(→‎{{header|REXX}}: add Version 2 with comments on dynamic scope)
Line 992:
 
=={{header|REXX}}==
===version 1===
In the REXX language, all variables are global, and only within PROCEDUREs are variables local (private), except for those identified
<br>via the &nbsp; '''expose''' &nbsp; option. &nbsp; There is a variant where the &nbsp; '''expose''' &nbsp; can have a list specified (along with variables and stems).
Line 1,027 ⟶ 1,028:
d = 55555555
return /*compliments to Jules Verne's Captain Nemo? */</lang>
===version 2 scope is DYNAMIC===
<lang rexx>a=1
b=2
c=3
Call p /* a Procedure */
Call s /* a subroutine */
Exit
p: Procedure Expose sigl b
Say 'in p sigl a b c' sigl a b c
Call s
Return
s:
Say 'in s sigl a b c' sigl a b c
Return</lang>
{{out}}
When s is called from p, it can only see the variable b that is exposed by p.
When called directly, it sees all the 'global variables a, b, and c.
<br>Assigning a variable in the subroutine s would similarly be seen or not in the main program.
<pre>in p sigl a b c 4 A 2 C
in s sigl a b c 9 A 2 C
in s sigl a b c 5 1 2 3</pre>
 
=={{header|Ruby}}==
2,299

edits