Scope modifiers: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: add Version 2 with comments on dynamic scope)
m (→‎version 2 scope is DYNAMIC: add assignment in s)
Line 1,033: Line 1,033:
c=3
c=3
Call p /* a Procedure */
Call p /* a Procedure */
Say 'in m a b c x' a b c x
Call s /* a subroutine */
Call s /* a subroutine */
Say 'in m a b c x' a b c x

Exit
Exit
p: Procedure Expose sigl b
p: Procedure Expose sigl b
Line 1,041: Line 1,044:
s:
s:
Say 'in s sigl a b c' sigl a b c
Say 'in s sigl a b c' sigl a b c
x=4
Return</lang>
Return </lang>
{{out}}
{{out}}
When s is called from p, it can only see the variable b that is exposed by p.
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.
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.
<br>Assigning a variable x in the subroutine s will similarly be seen or not in the main program.
<pre>in p sigl a b c 4 A 2 C
<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 12 A 2 C
in s sigl a b c 5 1 2 3</pre>
in m a b c x 1 2 3 X
in s sigl a b c 6 1 2 3
in m a b c x 1 2 3 4 </pre>


=={{header|Ruby}}==
=={{header|Ruby}}==