Scope modifiers: Difference between revisions
m
→version 2 scope is DYNAMIC: add assignment in s
Walterpachl (talk | contribs) (→{{header|REXX}}: add Version 2 with comments on dynamic scope) |
Walterpachl (talk | contribs) 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
<pre>in p sigl a b c 4 A 2 C
in s sigl a b c
in
in s sigl a b c 6 1 2 3
in m a b c x 1 2 3 4 </pre>
=={{header|Ruby}}==
|