Revision 28151
- Date:
- 2009/09/01 00:09:52
- Files:
Legend:
- Added
- Removed
- Modified
-
docs/Perl6/Spec/S02-bits.pod
14 14 Created: 10 Aug 2004 15 15 16 16 Last Modified: 31 Aug 2009 17 Version: 175 17 Version: 176 18 18 19 19 This document summarizes Apocalypse 2, which covers small-scale 20 20 lexical items and typological issues. (These Synopses also contain … … 2091 2091 user-defined variable from you. In fact, that's the default, and a 2092 2092 lexical variable must have the trait "C<is context>" to be 2093 2093 visible via C<CALLER>. (C<$_>, C<$!> and C<$/> are always 2094 contextual.) If the variable is not visible in the caller, it returns 2094 contextual, as are any variables whose declared names contain a C<*> twigil.) 2095 If the variable is not visible in the caller, it returns 2095 2096 failure. Variables whose names are visible at the point of the call but that 2096 2097 come from outside that lexical scope are controlled by the scope 2097 2098 in which they were originally declared as contextual. … … 2100 2101 it happens to be declared). Likewise C<< CALLER::CALLER::<$x> >> 2101 2102 depends only on the declaration of C<$x> visible in your caller's caller. 2102 2103 2103 Any lexical declared with the C<is context> trait is by default 2104 considered readonly outside the current lexical scope. You may 2105 add a trait argument of C<< <rw> >> to allow called routines to 2106 modify your value. C<$_>, C<$!>, and C<$/> are C<< context<rw> >> 2107 by default. In any event, the declaring scope can always access the 2108 variable as if it were an ordinary variable; the restriction on writing 2109 applies only to access via the C<*> twigil. 2104 User-defined contextual variables should generally be initialized with 2105 C<::=> unless it is necessary for variable to be modified. (Marking 2106 dynamic variables as readonly is very helpful in terms of sharing 2107 the same value among competing threads, since a readonly variable 2108 need not be locked.) 2110 2109 2111 2110 =item * 2112 2111 … … 2128 2127 semicolons as appropriate to the current operating system. Usage of 2129 2128 the C<%*FOO> form is currently undefined. 2130 2129 2131 Unlike C<CALLER>, C<CONTEXT> will see a contextual variable that is declared in 2132 the current scope, however it will not be writeable via C<CONTEXT> unless 2133 declared "C<< is context<rw> >>", even if the variable itself is 2134 modifiable in that scope. (If it is, you should just use the bare 2135 variable itself to modify it.) Note that C<$*_> will always see 2136 the C<$_> in the current scope, not the caller's scope. You may 2137 use C<< CALLER::<$*foo> >> to bypass a contextual definition of C<$foo> 2138 in your current context, such as to initialize it with the outer 2139 contextual value: 2130 Unlike C<CALLER>, C<CONTEXT> will see a contextual variable that is 2131 declared in the current scope, since it starts search 0 scopes up the 2132 stack rather than 1. You may, however, use C<< CALLER::<$*foo> >> 2133 to bypass a contextual definition of C<$*foo> in your current context, 2134 such as to initialize it with the outer contextual value: 2140 2135 2141 my $foo is context = CALLER::<$*foo>; 2136 my $*foo ::= CALLER::<$*foo>; 2142 2137 2143 The C<temp> maybe used on a contextual variable to perform a similar operation: 2138 The C<temp> maybe used without an initializer on a contextual variable 2139 to perform a similar operation: 2144 2140 2145 2141 temp $*foo; 2146 2142 2147 2143 The main difference is that by default it initializes the new 2148 C<$*foo> with its previous value, rather than the caller's value. 2149 The temporized contextual variable takes its read/write policy from 2150 the previous C<$*foo> container. 2144 C<$*foo> with its current value, rather than the caller's value. 2145 Also, it is allowed only on read/write contextual variables, since 2146 the only reason to make a copy of the outer value would be 2147 because you'd want to override it later and then forget the 2148 changes at the end of the current dynamic scope. 2151 2149 2152 2150 The C<CONTEXT> package is primarily for internal overriding of contextual 2153 2151 information, modelled on how environmental variables work among -
docs/Perl6/Spec/S06-routines.pod
15 15 16 16 Created: 21 Mar 2003 17 17 18 Last Modified: 24 Jul 2009 19 Version: 112 18 Last Modified: 31 Aug 2009 19 Version: 113 20 20 21 21 22 22 This document summarizes Apocalypse 6, which covers subroutines and the … … 2669 2669 2670 2670 C<< CALLER::<$varname> >> specifies the C<$varname> visible in 2671 2671 the dynamic scope from which the current block/closure/subroutine 2672 was called, provided that variable is declared with the "C<is context>" 2673 trait. (Implicit lexicals such as C<$_> are automatically 2674 assumed to be contextual.) 2672 was called, provided that variable carries the "C<context>" 2673 trait. (All variables with a C<*> twigil are automatically marked with the trait. 2674 Likewise certain implicit lexicals (C<$_>, C<$/>, and C<$!>) are so marked.) 2675 2675 2676 2676 C<< CONTEXT::<$varname> >> specifies the C<$varname> visible in the 2677 2677 innermost dynamic scope that declares the variable with the "C<is context>"