[svn:perl6-synopsis] r14345 - doc/trunk/design/syn
Author: larry Date: Wed Mar 14 09:03:15 2007 New Revision: 14345 Modified: doc/trunk/design/syn/S06.pod Log: Clarify that caller is not guaranteed to return a Routine context. Minor refactoring of context/caller section to avoid forward ref. Modified: doc/trunk/design/syn/S06.pod == --- doc/trunk/design/syn/S06.pod(original) +++ doc/trunk/design/syn/S06.podWed Mar 14 09:03:15 2007 @@ -13,9 +13,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 21 Mar 2003 - Last Modified: 12 Mar 2007 + Last Modified: 14 Mar 2007 Number: 6 - Version: 79 + Version: 80 This document summarizes Apocalypse 6, which covers subroutines and the @@ -1719,27 +1719,10 @@ You might think that that must be the current function's caller, but that's not necessarily so. This might return an outer block in our own routine, or even some function elsewhere that implements a -control operator on behalf of our block. +control operator on behalf of our block. To get outside your current +routine, see C below. -The C function is special-cased to pay attention only to -the current C scope. It is defined as navigating to the -innermost scope matching <&?ROUTINE> (which may be a no-op when -immediately inside a routine) and then going out one context from that: - -&caller ::= &context.assuming(&?ROUTINE,1); - -So to find where the current routine was called you can say: - -say " file ", caller.file, -" line ", caller.line; - -which is equivalent to: - -say " file ", CALLER::<$?FILE>, -" line ", CALLER::<$?LINE>; - -The C function always returns the immediate caller's context, -but the more general C function may be given arguments +The C function may be given arguments telling it which higher scope to look for. Each argument is processed in order, left to right. Note that C and C<0> are no-ops: @@ -1781,7 +1764,34 @@ $ctx = context; $ctx = context.context.context.context;# same -The returned context object supports at least the following methods: +The C function is special-cased to pay attention only to +the current C scope. It is defined as navigating to the +innermost scope matching C<&?ROUTINE> (which may be a no-op when +immediately inside a routine) and then going out one context from that: + +&caller ::= &context.assuming(&?ROUTINE,1); + +So to find where the current routine was called you can say: + +say " file ", caller.file, +" line ", caller.line; + +which is equivalent to: + +say " file ", CALLER::<$?FILE>, +" line ", CALLER::<$?LINE>; + +Note that one context out is I guaranteed to be a C +context. You must say C to get to the next-most-inner +routine, which is equivalent to C. +But C is not necessarily going to give you the +line number that your current routine was called from; you're rather +likely to get the line number of the topmost block that is executing +within that outer routine, where that block contains the call to +your routine. + +For either C or C, +the returned context object supports at least the following methods: .want .context
[svn:perl6-synopsis] r14346 - doc/trunk/design/syn
Author: larry Date: Wed Mar 14 11:08:52 2007 New Revision: 14346 Modified: doc/trunk/design/syn/S06.pod Log: Further refinement of caller semantics to dwim in displaced closure calls. Modified: doc/trunk/design/syn/S06.pod == --- doc/trunk/design/syn/S06.pod(original) +++ doc/trunk/design/syn/S06.podWed Mar 14 11:08:52 2007 @@ -1735,6 +1735,11 @@ $ctx = context(1,0,1,1); # my context's context's context's context $ctx = context($i); # $i'th context +Note also that negative numbers are allowed as long as you stay within +the existing context stack: + +$ctx = context(4,-1);# my context's context's context's context + Repeating any smartmatch just matches the same context again unless you intersperse a 1 to skip the current level: @@ -1764,12 +1769,15 @@ $ctx = context; $ctx = context.context.context.context;# same -The C function is special-cased to pay attention only to -the current C scope. It is defined as navigating to the -innermost scope matching C<&?ROUTINE> (which may be a no-op when -immediately inside a routine) and then going out one context from that: - -&caller ::= &context.assuming(&?ROUTINE,1); +The C function is special-cased to go outward just far enough +to escape from the current routine scope, after first ignoring any +inner blocks that are embedded, or are otherwise pretending to be "inline": + +&caller ::= &context.assuming({ !.inline }, 1); + +Note that this is usually the same as C, +but not always. A call to a returned closure might not even have +C<&?ROUTINE> in its dynamic scope anymore, but it still has a caller. So to find where the current routine was called you can say: @@ -1781,10 +1789,12 @@ say " file ", CALLER::<$?FILE>, " line ", CALLER::<$?LINE>; -Note that one context out is I guaranteed to be a C -context. You must say C to get to the next-most-inner -routine, which is equivalent to C. -But C is not necessarily going to give you the +Additional arguments to C are treated as navigational from the +calling context. One context out from your current routine is I +guaranteed to be a C context. You must say C +to get to the next-most-inner routine. + +Note that C is not necessarily going to give you the line number that your current routine was called from; you're rather likely to get the line number of the topmost block that is executing within that outer routine, where that block contains the call to @@ -1793,18 +1803,27 @@ For either C or C, the returned context object supports at least the following methods: -.want .context .caller +.leave +.want +.inline .my .file .line .subname -The C<.caller> method is subtly different from the C -function. Instead of looking up the current lexically scoped caller -by C<.context(&?ROUTINE,1)>, it just looks up the next matching dynamic -caller using C<.context(Routine,1)>. +The C<.context> and C<.caller> methods work the same as the functions +except that they are relative to the context supplied as invocant. +The C<.leave> method can force an immediate return from the +specified context. The C<.want> method returns known smart-matchable +characteristics of the specified context. + +The C<.inline> method says whether this block was entered implicitly +by some surrounding control structure. Any time you invoke a block or +routine explicitly with C<.()> this is false. However, it is defined +to be true for any block entered using dispatcher-level primitives +such as C<.callwith>, C<.callsame>, C<.nextwith>, or C<.nextsame>. The C<.my> method provides access to the lexical namespace in effect at the given dynamic context's current position. It may be used to look
[svn:perl6-synopsis] r14347 - doc/trunk/design/syn
Author: larry Date: Wed Mar 14 11:28:03 2007 New Revision: 14347 Modified: doc/trunk/design/syn/S02.pod Log: New "hyper" listop that is an explicitly parallelizing variant of "eager". Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podWed Mar 14 11:28:03 2007 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 13 Mar 2007 + Last Modified: 14 Mar 2007 Number: 2 - Version: 96 + Version: 97 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -2725,6 +2725,18 @@ =item * +A variant of C is the C list operator, which declares +not only that you want all the values generated now, but that you want +them badly enough that you don't care what order they're generated in. +That is, C requires sequential evaluation of the list, while +C requests (but does not require) parallel evaluation. In any +case, it declares that you don't care about the evaluation order. +(Conjecture: populating a hash from a hyper list of pairs could be done +as the results come in, such that some keys can be seen even before +the hyper is done. Thinking about Map-Reduce algorithms here...) + +=item * + Signatures on non-multi subs can be checked at compile time, whereas multi sub and method call signatures can only be checked at run time (in the absence of special instructions to the optimizer).
[svn:perl6-synopsis] r14348 - doc/trunk/design/syn
Author: larry Date: Wed Mar 14 11:44:47 2007 New Revision: 14348 Modified: doc/trunk/design/syn/S09.pod Log: autoindexing should assume parallelizability (that's a hard word to type) Modified: doc/trunk/design/syn/S09.pod == --- doc/trunk/design/syn/S09.pod(original) +++ doc/trunk/design/syn/S09.podWed Mar 14 11:44:47 2007 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 13 Sep 2004 - Last Modified: 27 Jan 2007 + Last Modified: 14 Mar 2007 Number: 9 - Version: 17 + Version: 18 =head1 Overview @@ -692,7 +692,7 @@ loop around the block of the closure that visits all the possible subscript values for that dimension (unless the parameter is actually supplied to the closure, in which case that is what is used as the -slice subscript). +slice subscript). This implicit loop is assumed to be parallelizable. So to write a typical tensor multiplication:
[svn:perl6-synopsis] r14349 - doc/trunk/design/syn
Author: larry Date: Wed Mar 14 12:12:20 2007 New Revision: 14349 Modified: doc/trunk/design/syn/S02.pod Log: Clarify adverbial use where infix expected. Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podWed Mar 14 12:12:20 2007 @@ -14,7 +14,7 @@ Date: 10 Aug 2004 Last Modified: 14 Mar 2007 Number: 2 - Version: 97 + Version: 98 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -1936,11 +1936,16 @@ Two or more adverbs can always be strung together without intervening punctuation anywhere a single adverb is acceptable. When used as -named arguments in an argument list, you may put comma between, +named arguments in an argument list, you I put comma between, because they're just ordinary named arguments to the function, and -a fatarrow pair would work the same. When modifying an operator -(that is, when one occurs where an operator is expected), you may -not put commas between, and the fatarrow form is not allowd. See S06. +a fatarrow pair would work the same. However, this comma is allowed +only when the first pair occurs where a term is expected. Where an +infix operator is expected, the adverb is always taken as modifying +the nearest preceding operator that is not hidden within parentheses, +and if you string together multiple such pairs, you may not put commas +between, since that would cause subsequent pairs to look like terms. +(The fatarrow form is not allowed at all in operator position.) +See S06 for the use of adverbs as named arguments. The negated form (C<:!a>) and the sigiled forms (C<:$a>, C<:@a>, C<:%a>) never take an argument and don't care what the next character is.