Scope modifiers: Difference between revisions

Content deleted Content added
→‎{{header|Racket}}: comment on phase levels
moved entries around to make the "R" languages in alphabetical order. -- ~~~~
Line 662: Line 662:
>>></lang>
>>></lang>
More information on the scope modifiers can be found [http://docs.python.org/3.0/reference/simple_stmts.html#grammar-token-global_stmt here].<br>
More information on the scope modifiers can be found [http://docs.python.org/3.0/reference/simple_stmts.html#grammar-token-global_stmt here].<br>

=={{header|REXX}}==
In the REXX language, all variables are local, and only within PROCEDUREs are variables local (private), except
<br>for those identified via the EXPOSE option. There is a variant where the EXPOSE can have a list specified.
<br>Any REXX variables in an external routine (program) aren't known.
<br>Note: the R4 REXX interpreter has an '''EXPOSEALL''' option that allows an external REXX subroutine to access the caller's local variables.
<br>There is a mechanism that allows external programs to access local REXX variables and is essentially restricted to
<br>assembler programs that use the REXXAPI interface.
<br>All labels (names of subroutines/functions/procedures) are global.
<br>If more than one identical label is specified, only the first label is recognized (and not considered an error).
<lang rexx>/*REXX program to display scope modifiers (for subroutines/functions). */
a=1/4
b=20
c=3
d=5
call SSN_571 d**4

/* at this point, A is defined and equal to .25 */
/* at this point, B is defined and equal to 40 */
/* at this point, C is defined and equal to 27 */
/* at this point, D is defined and equal to 5 */
/* at this point, FF isn't defined. */
/* at this point, EWE is defined and equal to 'female sheep' */
/* at this point, G is defined and equal to 625 */
exit /*stick a fork in it, we're done.*/
/*─────────────────────────────────────SSN_571 submarine, er, subroutine*/
SSN_571: procedure expose b c ewe g; parse arg g
b = b*2
c = c**3
ff = b+c
ewe = 'female sheep'
d = 55555555
return /*compliments to Jules Verne's Captain Nemo? */</lang>


=={{header|R}}==
=={{header|R}}==
Line 810: Line 777:


However, Racket identifier bindings do exist at particular phase levels (represented by an integer). Phase levels, to a first approximation, allow the separation of computations that occur at compile-time and run-time.
However, Racket identifier bindings do exist at particular phase levels (represented by an integer). Phase levels, to a first approximation, allow the separation of computations that occur at compile-time and run-time.

=={{header|REXX}}==
In the REXX language, all variables are local, and only within PROCEDUREs are variables local (private), except
<br>for those identified via the EXPOSE option. There is a variant where the EXPOSE can have a list specified.
<br>Any REXX variables in an external routine (program) aren't known.
<br>Note: the R4 REXX interpreter has an '''EXPOSEALL''' option that allows an external REXX subroutine to access the caller's local variables.
<br>There is a mechanism that allows external programs to access local REXX variables and is essentially restricted to
<br>assembler programs that use the REXXAPI interface.
<br>All labels (names of subroutines/functions/procedures) are global.
<br>If more than one identical label is specified, only the first label is recognized (and not considered an error).
<lang rexx>/*REXX program to display scope modifiers (for subroutines/functions). */
a=1/4
b=20
c=3
d=5
call SSN_571 d**4

/* at this point, A is defined and equal to .25 */
/* at this point, B is defined and equal to 40 */
/* at this point, C is defined and equal to 27 */
/* at this point, D is defined and equal to 5 */
/* at this point, FF isn't defined. */
/* at this point, EWE is defined and equal to 'female sheep' */
/* at this point, G is defined and equal to 625 */
exit /*stick a fork in it, we're done.*/
/*─────────────────────────────────────SSN_571 submarine, er, subroutine*/
SSN_571: procedure expose b c ewe g; parse arg g
b = b*2
c = c**3
ff = b+c
ewe = 'female sheep'
d = 55555555
return /*compliments to Jules Verne's Captain Nemo? */</lang>


=={{header|Tcl}}==
=={{header|Tcl}}==
===Variables===
===Variables===
In Tcl procedures, variables are local to the procedure unless explicitly declared otherwise (unless they contain namespace separators, which forces interpretation as namespace-scoped names). Declarations may be used to access variables in the global namespace, or the current namespace, or indeed any other namespace.
In Tcl procedures, variables are local to the procedure unless explicitly declared otherwise (unless they contain namespace separators, which forces interpretation as namespace-scoped names). Declarations may be used to access variables in the global namespace, or the current namespace, or indeed any other namespace.

{{works with|Tcl|8.5}}
{{works with|Tcl|8.5}}
<lang tcl>set globalVar "This is a global variable"
<lang tcl>set globalVar "This is a global variable"