Author: larry Date: Thu Mar 15 13:29:54 2007 New Revision: 14350 Modified: doc/trunk/design/syn/S02.pod
Log: Change CONTEXT:: vars to be consistent with new context() function. Clarify that CALLER:: can return variables defined elsewhere if visible there. Modified: doc/trunk/design/syn/S02.pod ============================================================================== --- doc/trunk/design/syn/S02.pod (original) +++ doc/trunk/design/syn/S02.pod Thu Mar 15 13:29:54 2007 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 14 Mar 2007 + Last Modified: 15 Mar 2007 Number: 2 - Version: 98 + Version: 99 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -1516,7 +1516,13 @@ lexical variable must have the trait "C<is context>" to be visible via C<CALLER>. (C<$_>, C<$!> and C<$/> are always contextual.) If the variable is not visible in the caller, it returns -failure. +failure. Variables whose names are visible at the point of the call but that +come from outside that lexical scope are controlled by the scope +in which they were originally declared, and so on transitively. +Hence the visibility of C<< CALLER::<$+foo> >> is determined where +C<$+foo> is actually declared, not by the caller's scope. Likewise +C<< CALLER::CALLER::<$x> >> depends only on the declaration of C<$x> +in your caller's caller. Any lexical declared with the C<is context> trait is by default considered readonly outside the current lexical scope. You may @@ -1529,7 +1535,8 @@ =item * The C<CONTEXT> pseudo-package is just like C<CALLER> except that -it scans outward through all dynamic scopes until it finds a +it starts in the current dynamic scope and from there +scans outward through all dynamic scopes until it finds a contextual variable of that name in that context's lexical scope. (Use of C<$+FOO> is equivalent to CONTEXT::<$FOO> or $CONTEXT::FOO.) If after scanning all the lexical scopes of each dynamic scope, @@ -1537,12 +1544,18 @@ If there is no variable in the C<*> package and the variable is a scalar, it then looks in C<%*ENV> for the identifier of the variable, that is, in the environment variables passed to program. If the -value is not found there, it returns failure. Note that C<$+_> is -always the same as CALLER::<$_> since all contexts have a C<$_> that -is automatically considered environmental. Note also that C<CONTEXT> -and C<$+> always skip the current scope, since you can always name -the variable directly without the C<CONTEXT> or C<+> if it's been -declared in the current lexical scope. +value is not found there, it returns failure. Unlike C<CALLER>, +C<CONTEXT> will see a contextual variable that is declared in +the current scope, however it will not be writeable via C<CONTEXT> unless +declared "C<< is context<rw> >>", even if the variable itself is +modifiable in that scope. (If it is, you should just use the bare +variable itself to modify it.) Note that C<$+_> will always see +the C<$_> in the current scope, not the caller's scope. You may +use C<< CALLER::<$+foo> >> to bypass a contextual definition of C<$foo> +in your current context, such as to initialize it with the outer +contextual value: + + my $foo is context = CALLER::<$+foo>; The C<CONTEXT> package is only for internal overriding of contextual information, modelled on how environmental variables work among