Author: larry Date: Wed Jan 2 11:30:16 2008 New Revision: 14478 Modified: doc/trunk/design/syn/S03.pod doc/trunk/design/syn/S06.pod
Log: Rationalize migration strategy from Perl 5 to Perl 6 using transitional p5=> operator Modified: doc/trunk/design/syn/S03.pod ============================================================================== --- doc/trunk/design/syn/S03.pod (original) +++ doc/trunk/design/syn/S03.pod Wed Jan 2 11:30:16 2008 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 8 Mar 2004 - Last Modified: 31 Dec 2007 + Last Modified: 2 Jan 2008 Number: 3 - Version: 125 + Version: 126 =head1 Overview @@ -48,7 +48,7 @@ Conditional ?? !! ff fff Item assignment = := ::= => += -= **= xx= .= Loose unary true not - Comma operator , + Comma operator , p5=> List infix Z minmax X X~X X*X XeqvX List prefix = : print push say die map substr ... [+] [*] any $ @ Loose and and andthen @@ -1346,6 +1346,28 @@ Unlike in Perl 5, comma operator never returns the last value. (In item context it returns a list instead.) +=item * + +C<< infix:«p5=>» >>, the Perl 5 fatarrow + +This operator, which behaves exactly like the Perl 5 fatarrow in being +equivalent to a comma, is purely for easier migration from Perl 5 +to Perl 6. It is not intended for use by programmers in fresh code; +it is for use by the p5-to-p6 translator to preserve Perl 5 argument +passing semantics without losing the intent of the notation. + +This operator is purposefully ugly and easy to search for. Note that, +since the operator is equivalent to a comma, arguments come in as +positional pairs rather than named arguments. Hence, if you have +a Perl 5 sub that manually handles named argument processing by +assigning to a hash, it will continue to work. If, however, you edit +the C<< p5=> >> operator in an argument list to Perl 6's C<< => >> +operator, it becomes a real named argument, so you must also change +the called sub to handle real named args, since the named pair will no +longer come in via C<@_>. You can either name your formal parameters +explicitly if there is an explicit signature, or pull them out of C<%_> +rather than C<@_> if there is no explicit signature. + =back =head2 List infix precedence Modified: doc/trunk/design/syn/S06.pod ============================================================================== --- doc/trunk/design/syn/S06.pod (original) +++ doc/trunk/design/syn/S06.pod Wed Jan 2 11:30:16 2008 @@ -13,9 +13,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 21 Mar 2003 - Last Modified: 26 Oct 2007 + Last Modified: 2 Jan 2008 Number: 6 - Version: 90 + Version: 91 This document summarizes Apocalypse 6, which covers subroutines and the @@ -124,18 +124,37 @@ sub foo {...} -Arguments implicitly come in via the C<@_> array, but they are C<readonly> -aliases to actual arguments: +This is equivalent to - sub say { print qq{"@_[]"\n}; } # args appear in @_ + sub foo ([EMAIL PROTECTED], *%_) {...} - sub cap { $_ = uc $_ for @_ } # Error: elements of @_ are read-only +Positional arguments implicitly come in via the C<@_> array, but +unlike in Perl 5 they are C<readonly> aliases to actual arguments: -If you need to modify the elements of C<@_>, declare the array explicitly -with the C<is rw> trait: + sub say { print qq{"@_[]"\n}; } # args appear in @_ - sub swap ([EMAIL PROTECTED] is rw) { @_[0,1] = @_[1,0] } + sub cap { $_ = uc $_ for @_ } # Error: elements of @_ are read-only +Also unlike in Perl 5, Perl 6 has true named arguments, which come in +via C<%_> instead of C<@_>. (To construct pseudo-named arguments that +come in via C<@_> as in Perl 5, the p5-to-p6 translator will use the ugly +C<< p5=> >> operator instead of Perl 6's C<< => >> Pair constructor.) + +If you need to modify the elements of C<@_> or C<%_>, declare the +array or hash explicitly with the C<is rw> trait: + + sub swap ([EMAIL PROTECTED] is rw, *%_ is rw) { @_[0,1] = @_[1,0]; %_<status> = "Q:S"; } + +Note: the "rw" container trait is automatically distributed to the +individual elements by the the slurpy star even though there's no +actual array or hash passed in. More precisely, the slurpy star +means the declared formal parameter is I<not> considered readonly; only +its elements are. See L</Parameters and arguments> below. + +Note also that if the sub's block contains placeholder variables (such +as C<$^foo>), it is considered to have a formal signature already, so +no implicit bindings to C<@_> or C<%_> are assumed (nor is an explicit +signature allowed.) So in that case, this section does not apply. =head2 Blocks