Author: lwall Date: 2010-03-26 08:38:16 +0100 (Fri, 26 Mar 2010) New Revision: 30205
Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S03-operators.pod docs/Perl6/Spec/S05-regex.pod docs/Perl6/Spec/S06-routines.pod docs/Perl6/Spec/S12-objects.pod Log: [specs] Make it clear that pairs are *not* related to subscripts, but the corresponding fatarrow semantics in particular, name extenders are just strings or list of strings, properly indicated by :<> or :() in most cases (this includes all operator names). Forbid name extension using :{}, and since names may no longer be extended with :{}, we can free up that notation for supplying a closure as a first argument to a method without an intervening space. (We can't also get rid of the colon, or it's a hash subscript.) Modified: docs/Perl6/Spec/S02-bits.pod =================================================================== --- docs/Perl6/Spec/S02-bits.pod 2010-03-26 04:10:22 UTC (rev 30204) +++ docs/Perl6/Spec/S02-bits.pod 2010-03-26 07:38:16 UTC (rev 30205) @@ -13,8 +13,8 @@ Created: 10 Aug 2004 - Last Modified: 12 Mar 2010 - Version: 208 + Last Modified: 26 Mar 2010 + Version: 209 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -2919,14 +2919,14 @@ infix:<+> infix:<<+>> infix:«+» - infix:['+'] + infix:('+') Despite the appearance as a subscripting form, these names are resolved not at run time but at compile time. The pseudo-subscripts need not be simple scalars. These are extended with the same two-element list: infix:<?? !!> - infix:['??','!!'] + infix:('??','!!') An identifier may be extended with multiple named identifier extensions, in which case the names matter but their order does not. @@ -3280,10 +3280,10 @@ 16 => $somevalue :16($somevalue) radix conversion function '' => $x :($x) arglist or signature literal '' => ($x,$y) :($x,$y) arglist or signature literal - '' => <x> :<x> identifier extension - '' => «x» :«x» identifier extension - '' => [$x,$y] :[$x,$y] identifier extension - '' => { .say } :{ .say } adverbial block + '' => <x> :<x> name extension + '' => «x» :«x» name extension + '' => ($x,$y) :($x,$y) name extension + '' => { .say } :{ .say } adverbial block (not allowed on names) All of the adverbial forms (including the normal ones with identifier keys) are considered special tokens and are recognized @@ -3314,6 +3314,22 @@ standard Perl 6 grammar knows the current set of infix operators, for instance.) +Only identifiers that produce a list of one or more values (preferably +strings) are allowed as name extensions; in particular, closures +do not qualify as values, so the C<:{...}> form is not allowed as a +name extender. In particular, this frees up the block form after a method +name, so it allows us to parse a block as a method argument: + + @stuff.sort:{ +$_ }.map:{ $_ * 2 } + +These might look like it is using pairs, but it is really equivalent to + + @stuff.sort: { +$_ }.map: { $_ * 2 } + +and the colons are not introducing pairs, but rather introducing +the argument list of the method. (In any other location, C<:{...}> +would be taken as a pair mapping the null key to a closure.) + Either fatarrow or adverbial pair notation may be used to pass named arguments as terms to a function or method. After a call with parenthesized arguments, only the adverbial syntax may be used to pass @@ -3327,8 +3343,9 @@ Note that (as usual) the C<{...}> form (either identifier-based or special) can indicate either a closure or a hash depending on -the contents. It does I<not> always indicate a subscript despite -being parsed as one. (The function to which it is passed can I<use> +the contents. It does I<not> indicate a subscript, since C<:key{}> is +really equivalent to C<key => {}>, and the braces are not behaving +as a postfix at all. (The function to which it is passed can I<use> the value as a subscript if it chooses, however.) Note also that the C<< <a b> >> form is not a subscript and is @@ -4414,16 +4431,16 @@ category:<prefix> prefix:<+> circumfix:<[ ]> [ @x ] dotty:<.=> $obj.=method - infix_circumfix_meta_operator:{'»','«'} @a »+« @b + infix_circumfix_meta_operator:('»','«') @a »+« @b infix_postfix_meta_operator:<=> $x += 2; infix_prefix_meta_operator:<!> $x !~~ 2; infix:<+> $x + $y package_declarator:<role> role Foo; postcircumfix:<[ ]> $x[$y] or $x.[$y] - postfix_prefix_meta_operator:{'»'} @array »++ + postfix_prefix_meta_operator:('»') @array »++ postfix:<++> $x++ - prefix_circumfix_meta_operator:{'[',']'} [*] - prefix_postfix_meta_operator:{'«'} -« @magnitudes + prefix_circumfix_meta_operator:('[',']') [*] + prefix_postfix_meta_operator:('«') -« @magnitudes prefix:<!> !$x (and $x.'!') q_backslash:<\\> '\\' qq_backslash:<n> "\n" Modified: docs/Perl6/Spec/S03-operators.pod =================================================================== --- docs/Perl6/Spec/S03-operators.pod 2010-03-26 04:10:22 UTC (rev 30204) +++ docs/Perl6/Spec/S03-operators.pod 2010-03-26 07:38:16 UTC (rev 30205) @@ -15,8 +15,8 @@ Created: 8 Mar 2004 - Last Modified: 19 Mar 2010 - Version: 199 + Last Modified: 26 Mar 2010 + Version: 200 =head1 Overview @@ -796,7 +796,7 @@ =item * -C<< infix:{'+&'} >>, numeric bitwise and +C<< infix:('+&') >>, numeric bitwise and $x +& $y @@ -805,13 +805,13 @@ =item * -C<< infix:{'+<'} >>, numeric shift left +C<< infix:('+<') >>, numeric shift left $integer +< $bits =item * -C<< infix:{'+>'} >>, numeric shift right +C<< infix:('+>') >>, numeric shift right $integer +> $bits @@ -836,13 +836,13 @@ =item * -C<< infix:{'~<'} >>, buffer bitwise shift left +C<< infix:('~<') >>, buffer bitwise shift left $buf ~< $bits =item * -C<< infix:{'~>'} >>, buffer bitwise shift right +C<< infix:('~>') >>, buffer bitwise shift right $buf ~> $bits @@ -1573,7 +1573,7 @@ =item * -C<< infix:{'=>'} >>, Pair constructor +C<< infix:('=>') >>, Pair constructor foo => 1, bar => "baz" @@ -2573,7 +2573,7 @@ =item * C<< -> >> becomes C<.>, like the rest of the world uses. There is -a pseudo C<< postfix:{'->'} >> operator that produces a compile-time +a pseudo C<< postfix:('->') >> operator that produces a compile-time error reminding Perl 5 users to use dot instead. (The "pointy block" use of C<< -> >> in Perl 5 requires preceding whitespace when the arrow could be confused with a postfix, that is when an infix is expected. @@ -4219,7 +4219,7 @@ or you can let the system autogenerate one for you based on the corresponding infix operator, probably by currying: - # (examples, actual system may define prefix:[**] instead) + # (examples, actual system may define prefix:(**) instead) &prefix:<[*]> ::= &reduce.assuming(&infix:<*>, 1); &prefix:<[**]> ::= &reducerev.assuming(&infix:<**>); @@ -4325,7 +4325,7 @@ User-defined operators may define their own identity values, but there is no explicit identity property. The value is implicit in the behavior of the 0-arg reduce, so mathematical code wishing to find -the identity value for an operation can call C<prefix:{"[$opname]"}()> +the identity value for an operation can call C<prefix:("[$opname]")()> to discover it. To call some other non-infix function as a reduce operator, you may Modified: docs/Perl6/Spec/S05-regex.pod =================================================================== --- docs/Perl6/Spec/S05-regex.pod 2010-03-26 04:10:22 UTC (rev 30204) +++ docs/Perl6/Spec/S05-regex.pod 2010-03-26 07:38:16 UTC (rev 30205) @@ -2439,11 +2439,11 @@ Therefore C<$()> is usually just the entire match string, but you can override that by calling C<make> inside a regex: - my $moose = $(m:{ + my $moose = $(m[ <antler> <body> { make Moose.new( body => $<body>.attach($<antler>) ) } # match succeeds -- ignore the rest of the regex - }); + ]); This puts the new abstract node into C<$/.ast>. An AST node may be of any type. Modified: docs/Perl6/Spec/S06-routines.pod =================================================================== --- docs/Perl6/Spec/S06-routines.pod 2010-03-26 04:10:22 UTC (rev 30204) +++ docs/Perl6/Spec/S06-routines.pod 2010-03-26 07:38:16 UTC (rev 30205) @@ -16,8 +16,8 @@ Created: 21 Mar 2003 - Last Modified: 19 Mar 2010 - Version: 130 + Last Modified: 26 Mar 2010 + Version: 131 This document summarizes Apocalypse 6, which covers subroutines and the new type system. @@ -367,14 +367,13 @@ Operators are just subroutines with special names and scoping. An operator name consists of a grammatical category name followed by a single colon followed by an operator name specified as if it were -a hash subscript (but evaluated at compile time). So any of these -indicates the same binary addition operator: +a one or more strings. So any of these indicates the same binary addition operator: infix:<+> infix:«+» infix:<<+>> - infix:{'+'} - infix:{"+"} + infix:('+') + infix:("+") Use the C<&> sigil just as you would on ordinary subs. @@ -393,7 +392,7 @@ operator. sub circumfix:<LEFTDELIM RIGHTDELIM> ($contents) {...} - sub circumfix:{'LEFTDELIM','RIGHTDELIM'} ($contents) {...} + sub circumfix:('LEFTDELIM','RIGHTDELIM') ($contents) {...} Contrary to Apocalypse 6, there is no longer any rule about splitting an even number of characters. You must use a two-element slice. Such names @@ -403,7 +402,7 @@ do. (Symbolic references do not count as direct subscripts since they go through a parsing process.) The canonical form always uses angle brackets and a single space between slice elements. The elements -are not escaped, so C<< PKG::circumfix:{'<','>'} >> is canonicalized +are not escaped, so C<< PKG::circumfix:('<','>') >> is canonicalized to C<<< PKG::{'circumfix:<< >>'} >>>, and decanonicalizing always involves stripping the outer angles and splitting on space, if any. This works because a hash key knows how long it is, so there's no @@ -1848,16 +1847,16 @@ circumfix:<( )> dotty:<.> infix:<+> - infix_circumfix_meta_operator:{'»','«'} + infix_circumfix_meta_operator:('»','«') infix_postfix_meta_operator:<=> infix_prefix_meta_operator:<!> package_declarator:<class> postcircumfix:<( )> postfix:<++> - postfix_prefix_meta_operator:{'»'} + postfix_prefix_meta_operator:('»') prefix:<++> - prefix_circumfix_meta_operator:{'[',']'} - prefix_postfix_meta_operator:{'«'} + prefix_circumfix_meta_operator:('[',']') + prefix_postfix_meta_operator:('«') q_backslash:<\\> qq_backslash:<n> quote_mod:<c> Modified: docs/Perl6/Spec/S12-objects.pod =================================================================== --- docs/Perl6/Spec/S12-objects.pod 2010-03-26 04:10:22 UTC (rev 30204) +++ docs/Perl6/Spec/S12-objects.pod 2010-03-26 07:38:16 UTC (rev 30205) @@ -13,8 +13,8 @@ Created: 27 Oct 2004 - Last Modified: 7 Mar 2010 - Version: 99 + Last Modified: 26 Mar 2010 + Version: 100 =head1 Overview @@ -393,11 +393,11 @@ not C<Callable>, C<Iterable>, or C<List>. Another form of indirection relies on the fact that operators are named -using a variant on hash subscript notation, which gives you these forms: +using a variant on pair notation, which gives you these forms: - $x.infix:{$op}($y) - $x.prefix:{$op} - $x.postfix:{$op} + $x.infix:($op)($y) + $x.prefix:($op) + $x.postfix:($op) Generally you see these with the literal angle bracket form of subscript: @@ -416,8 +416,8 @@ But it's probably better to spell out the syntactic category when the actual operator is not obvious: - $x.infix:{$op}($y) - $x.prefix:{$op} + $x.infix:($op)($y) + $x.prefix:($op) You must use a special syntax to call a private method: @@ -453,13 +453,29 @@ .doit(1): 2,3 # okay, one argument plus list .doit (): 1,2,3 # ILLEGAL (two terms in a row) -In particular, this allows us to pass a closure in addition to the +In particular, this allows us to pass a final closure in addition to the "normal" arguments: .doit: { $^a <=> $^b } # okay .doit(): { $^a <=> $^b } # okay .doit(1,2,3): { $^a <=> $^b } # okay + .doit(1,2,3): { $^a <=> $^b } # okay +Normally a space is required after the colon to disambiguate what +follows from from a pair that extends the previous name. However, +names may not be extended with the C<:{}> pair notation, and therefore +it is allowed to drop the space after the colon if the first argument +to the method is a closure. Hence, any of the above may be written +without the space after the colon: + + .doit:{ $^a <=> $^b } # okay + .doit():{ $^a <=> $^b } # okay + .doit(1,2,3):{ $^a <=> $^b } # okay + .doit(1,2,3):{ $^a <=> $^b } # okay + +These are parsed as there were a space there, so the argument list may +continue if the closure is followed by a comma. + In case of ambiguity between indirect object notation and dot form, the nearest thing wins: @@ -491,6 +507,13 @@ @list.grep({ $_ % 2 }).map({ $_ - 1 }).say +Since the colon does not require a space in this case, and it looks +kinda funny to put it, it may be clearer to omit the space to make +the method calls on the right look more like they attach to the term +on the left in one cascade of method calls: + + @list.grep:{ $_ % 2 }.map:{ $_ - 1 }.say + Methods (and subs) may be declared as lvalues with C<is rw>. You can use an argumentless C<rw> method anywhere you can use a variable, including in C<temp> and C<let> statements. (In fact, you can use an