Topic variable: Difference between revisions

→‎{{header|Raku}}: more verbiage about scopes
(→‎{{header|Raku}}: Add some more verbiage about relative scopes)
(→‎{{header|Raku}}: more verbiage about scopes)
Line 552:
10 1000 1000000 31.622776601683793 9.965784284662087 10 Outside</pre>
Note: that the $_ inside the 'map' block is different than the $_ set in the 'for' block. The scope of the <tt>$_</tt> variable is always lexical in Raku, though a function can access topics in other scopes by specifying the scope: <code>CALLER::<$_></code> from within a subroutine, <code>OUTER::<$_></code> for the next enclosing block, <code>UNIT::<$_></code> for the outermost block in a compilation unit, etc. The scope modifiers may be stacked: <code>CALLER::OUTER::<$_></code> would be the topic variable of the next outer block of the current subroutines caller block.
 
The scope modifiers can only flow outward. There is no way to access the topic of a block enclosed within the current scope or in a separate scope 'branch'.
 
Also note: '''Any''' variable in other scopes can be accessed this way. This is just pointing out that the default (topic) variable also has this property.
 
=={{header|REXX}}==
10,333

edits