Scope modifiers: Difference between revisions

m
(→‎{{header|REXX}}: add Version 2 with comments on dynamic scope)
m (→‎version 2 scope is DYNAMIC: add assignment in s)
Line 1,033:
c=3
Call p /* a Procedure */
Say 'in m a b c x' a b c x
Call s /* a subroutine */
Say 'in m a b c x' a b c x
 
Exit
p: Procedure Expose sigl b
Line 1,041 ⟶ 1,044:
s:
Say 'in s sigl a b c' sigl a b c
x=4
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 x in the subroutine s wouldwill 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 912 A 2 C
in s siglm a b c 5x 1 2 3</pre> X
in s sigl a b c 6 1 2 3
in m a b c x 1 2 3 4 </pre>
 
=={{header|Ruby}}==
2,295

edits