Author: lwall Date: 2008-12-28 04:17:03 +0100 (Sun, 28 Dec 2008) New Revision: 24656
Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S06-routines.pod docs/Perl6/Spec/S13-overloading.pod Log: [Spec] get rid of some fossil uses of * spotted by masak++ Modified: docs/Perl6/Spec/S02-bits.pod =================================================================== --- docs/Perl6/Spec/S02-bits.pod 2008-12-27 23:47:44 UTC (rev 24655) +++ docs/Perl6/Spec/S02-bits.pod 2008-12-28 03:17:03 UTC (rev 24656) @@ -12,9 +12,9 @@ Maintainer: Larry Wall <la...@wall.org> Date: 10 Aug 2004 - Last Modified: 19 Nov 2008 + Last Modified: 27 Dec 2008 Number: 2 - Version: 143 + Version: 144 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -777,8 +777,7 @@ =item * -Ordinarily a term beginning with C<*> indicates a global function -or type name, but by itself, the C<*> term captures the notion of +The C<*> character as a standalone term captures the notion of "Whatever", which is applied lazily by whatever operator it is an argument to. Generally it can just be thought of as a "glob" that gives you everything it can in that argument position. For instance: @@ -805,6 +804,28 @@ is effectively immutable, the optimizer is free to recognize C<*> and optimize in the context of what operator it is being passed to. +Most of the built-in numeric operators treat an argument of C<*> as +indicating the desire to create a function of a single unknown, so: + + * - 1 + +produces a result similar to: + + { $^x - 1 } + +except that the result is still of type C<Whatever>. + +A value of type C<Whatever> may therefore be called as a function of +one argument. The bare C<*> form therefore represents the identify function: + + *(42) == 42 + (* + 1)(42) == 43 + +Note that the final element of an array is subscripted as C<@a[*-1]>, +which means that when the subscripting operation calls the C<Whatever> +object, it supplies an argument indicating the number of elements in +(that dimension of) the array. See S09. + A variant of C<*> is the C<**> term. It is generally understood to be a multidimension form of C<*> when that makes sense. @@ -1882,7 +1903,7 @@ values into C<%*ENV> to change what subprocesses see: temp %*ENV{LANG} = $+LANG; # may be modified by parent - system "greet"; + run "greet"; =item * Modified: docs/Perl6/Spec/S06-routines.pod =================================================================== --- docs/Perl6/Spec/S06-routines.pod 2008-12-27 23:47:44 UTC (rev 24655) +++ docs/Perl6/Spec/S06-routines.pod 2008-12-28 03:17:03 UTC (rev 24656) @@ -13,9 +13,9 @@ Maintainer: Larry Wall <la...@wall.org> Date: 21 Mar 2003 - Last Modified: 21 Nov 2008 + Last Modified: 27 Dec 2008 Number: 6 - Version: 97 + Version: 98 This document summarizes Apocalypse 6, which covers subroutines and the @@ -259,42 +259,35 @@ =head2 Globally scoped subroutines Subroutines and variables can be declared in the global namespace, and are -thereafter visible everywhere in a program. +thereafter visible everywhere in a program via the GLOBAL package. They +may be made directly visible by importation. -Global subroutines and variables are normally referred to by prefixing -their identifiers with C<*> (short for "C<GLOBAL::>"). The C<*> -is required on the declaration unless the C<GLOBAL> namespace can be -inferred some other way, but the C<*> may be omitted on use if the -reference is unambiguous: +Global subroutines and variables are normally referred to use of the C<*> twigil +(short for "C<GLOBAL::>"). $*next_id = 0; - sub *saith($text) { print "Yea verily, $text" } + sub GLOBAL::saith($text) { print "Yea verily, $text" } module A { - my $next_id = 2; # hides any global or package $next_id - saith($next_id); # print the lexical $next_id; - saith($*next_id); # print the global $next_id; + my $next_id = 2; # hides any global or package $next_id + &*saith($next_id); # print the lexical $next_id; + &*saith($*next_id); # print the global $next_id; } module B { - saith($next_id); # Unambiguously the global $next_id + use GLOBAL <$next_id>; + &*saith($next_id); # Unambiguously the global $next_id } -However, under stricture (the default for most code), the C<*> is required -on variable references. It's never required on sub calls, and in fact, -the syntax +=head2 Dynamically scoped subroutines - $x = *saith($y); +Similarly, you may define contextual subroutines: -is illegal, because a C<*> where a term is expected is always parsed -as the "whatever" token. If you really want to use a C<*>, you must -also use the sigil along with the twigil: + my sub myfunc ($x) is context { ... } - $x = &*saith($y); +This may then be invoked via the syntax for contextual variables: -Only the name is installed into the C<GLOBAL> package by C<*>. To define -subs completely within the scope of the C<GLOBAL> namespace you should -use "C<package GLOBAL {...}>" around the declaration. + &+myfunc(42); =head2 Lvalue subroutines Modified: docs/Perl6/Spec/S13-overloading.pod =================================================================== --- docs/Perl6/Spec/S13-overloading.pod 2008-12-27 23:47:44 UTC (rev 24655) +++ docs/Perl6/Spec/S13-overloading.pod 2008-12-28 03:17:03 UTC (rev 24656) @@ -12,9 +12,9 @@ Maintainer: Larry Wall <la...@wall.org> Date: 2 Nov 2004 - Last Modified: 8 Oct 2008 + Last Modified: 27 Dec 2008 Number: 13 - Version: 11 + Version: 12 =head1 Overview @@ -47,20 +47,23 @@ declarations of the C<multi> routines themselves. To overload an existing built-in sub, say something like: - multi sub *uc (TurkishStr $s) {...} + multi sub uc (TurkishStr $s) {...} -Now if you call C<uc()> on any Turkish string, it will call your function -rather than the built-in one. Putting the C<multi> into the C<*> -namespace makes it show up in everyone's packages, but as long as no one -else defines a version of C<uc> on C<TurkishStr>, there's no collision. +A multi is automatically exported if goverened by a proto that is exported. +It may also be explicitly exported: + multi sub uc (TurkishStr $s) is exported {...} + +Now if you call C<uc()> on any Turkish string, it will call your +function rather than the built-in one. + The types of the parameters are included in the I<longname> of any C<multi> sub or method. So if you want to overload string concatenation for Arabic strings so you can handle various ligatures, you can say: - multi sub *infix:<~>(ArabicStr $s1, ArabicStr $s2) {...} - multi sub *infix:<~>(Str $s1, ArabicStr $s2) {...} - multi sub *infix:<~>(ArabicStr $s1, Str $s2) {...} + multi sub infix:<~>(ArabicStr $s1, ArabicStr $s2) {...} + multi sub infix:<~>(Str $s1, ArabicStr $s2) {...} + multi sub infix:<~>(ArabicStr $s1, Str $s2) {...} The C<use overload> syntax had one benefit over PerlĀ 6's syntax in that it was easy to alias several different operators to the same service @@ -91,11 +94,9 @@ variable within the body, for instance, there would only be one of them. -Note the lack of C<*> on the definitions above. That means this definition -of addition is syntactically in effect only within the scope in which -C<< infix:<+> >> is defined or imported. Similar constraints apply -to lexically scoped multi subs. Generally you want to put your multi -subs into the C<*> space, however, so that they work everywhere. +A multi is in effect only within the scope in which it is defined or +imported. Generally you want to put your multi subs into a package +that will be imported wherever they are needed. When you use the multiple signature syntax, the alternate signatures must all bind the same set of formal variable names, though they