Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[svn:perl6-synopsis] r13540 - doc/trunk/design/syn

7 views
Skip to first unread message

la...@cvs.perl.org

unread,
Jan 27, 2007, 3:59:59 AM1/27/07
to perl6-l...@perl.org
Author: larry
Date: Sat Jan 27 00:59:58 2007
New Revision: 13540

Modified:
doc/trunk/design/syn/S03.pod

Log:
Major reorganization of S03.


Modified: doc/trunk/design/syn/S03.pod
==============================================================================
--- doc/trunk/design/syn/S03.pod (original)
+++ doc/trunk/design/syn/S03.pod Sat Jan 27 00:59:58 2007
@@ -2,7 +2,7 @@

=head1 TITLE

-Synopsis 3: Summary of Perl 6 Operators
+Synopsis 3: Perl 6 Operators

=head1 AUTHOR

@@ -12,30 +12,1292 @@

Maintainer: Larry Wall <la...@wall.org>
Date: 8 Mar 2004
- Last Modified: 22 Jan 2007
+ Last Modified: 26 Jan 2007
Number: 3
- Version: 90
+ Version: 91
+
+=head1 Overview
+
+For a summary of the changes from Perl 5, see L</Changes to Perl 5 operators>.
+
+=head1 Operator precedence
+
+Not counting terms and terminators, Perl 6 has 20 operator precedence
+levels. (Perl 5 has 23!) Here we list the levels from "tightest" to
+"loosest", along with a few examples of each level:
+
+ Level Examples
+ ===== ========
+ Terms 42 3.14 "eek" qq["foo"] $x :!verbose
+ Method postfix .meth .+ .? .* .() .[] .{} .<> .«» .:: .= .^
+ Autoincrement ++ --
+ Exponentiation **
+ Symbolic unary ! + - ~ ? $ @ % & | +^ ~^ ?^ \ ^ =
+ Multiplicative * / % x xx +& +< +> ~& ~< ~> ?& div mod
+ Additive + - ~ +| +^ ~| ~^ ?| ?^
+ Junctive and (all) &
+ Junctive or (any) | ^
+ Named unary rand sleep abs -e -r -w -x
+ Nonchaining binary but does <=> leg cmp .. ..^ ^.. ^..^ ff fff
+ Chaining binary != == < <= > >= eq ne lt le gt ge ~~ === eqv !eqv
+ Tight and &&
+ Tight or || ^^ // min max
+ Conditional ?? !!
+ Item assignment = := ::= => += -= **= xx= .=
+ Loose unary true not
+ List ops , = print push say die map substr ... [+] [*] any all
+ List infix ¥ <== ==> minmax X XX X~X X*X XeqvX
+ Loose and and
+ Loose or or xor err
+ Terminator ; {...}, modifiers, unmatched ), ], }
+
+If you don't see your favorite operator there, the following
+sections cover all the operators in precedence order. Basic operator
+descriptions are here; special topics are covered afterwards.
+
+=head2 Term precedence
+
+This isn't really a precedence level, but it's in here because no operator
+can have tighter precedence than a term. See S02 for longer descriptions of
+various terms.
+
+=over
+
+=item *
+
+Int literal
+
+ 42
+
+=item *
+
+Num literal
+
+ 3.14
+
+=item *
+
+Non-interpolating Str literal
+
+ '$100'
+
+=item *
+
+Interpolating Str literal
+
+ "Answer = $answer\n"
+
+=item *
+
+Generalized Str literal
+
+ q["$100"]
+ qq["$answer"]
+
+=item *
+
+Array composer
+
+ [1,2,3]
+
+=item *
+
+Hash composer
+
+ { a => 42 }
+
+=item *
+
+Closure
+
+ {...}
+
+=item *
+
+Capture composer
+
+ \(@a,$b,%c)
+
+=item *
+
+Sigiled variables
+
+ $x
+ @y
+ %z
+ $^a
+ $?FILE
+ @@multidim
+ &func
+ &div:(Int, Int --> Int)
+
+=item *
+
+Sigils as contextualizer functions
+
+ $()
+ @()
+ %()
+ &()
+ @@()
+
+=item *
+
+Regexes in quote-like notation
+
+ /abc/
+ rx:i[abc]
+ s/foo/bar/
+
+=item *
+
+Transliterations
+
+ tr/a..z/A..Z/;
+
+Note ranges use C<..> rather than C<->.
+
+=item *
+
+Type names
+
+ Num
+ ::Some::Package
+
+=item *
+
+Circumfixed subexpressions
+
+ (1+2)
+
+Circumfixed items are treated like a term on the outside.
+
+=item *
+
+Function call
+
+ a(1)
+
+=item *
+
+Pair composers
+
+ :by(2)
+ :!verbose
+
+=item *
+
+Signature literal
+
+ :(Dog $self:)
+
+=item *
+
+Method call with implicit invocant
+
+ .meth # call on $_
+ .=meth # modify $_
+
+=item *
+
+Listop (leftward)
+
+ 4,3, sort 2,1 # 4,3,1,2
+
+As in Perl 5, a list operator looks like a term to the expression on
+its left, so it binds tighter than comma on the left but looser than
+comma on the right--see List operator precedence below.
+
+=back
+
+=head2 Method postfix precedence
+
+All method postfixes start with a dot, though the dot is optional
+for subscripts. Since these are the tightest standard operator,
+you can often think of a series of method calls as a single term that
+merely expresses a complicated name.
+
+See S12 for more discussion of single dispatch method calls.
+
+=over
+
+=item *
+
+Standard single-dispatch method calls
+
+ $obj.meth
+
+=item *
+
+Variants of standard single-dispatch method call
+
+ $obj.+meth
+ $obj.?meth
+ $obj.*meth
+
+In addition to the ordinary C<.> method invocation, there are variants
+C<.*>, C<.?>, and C<.+> to control how multiple related methods of
+the same name are handled.
+
+=item *
+
+Class-qualified method call
+
+ $obj.::Class::meth
+
+=item *
+
+Mutating method call
+
+ $obj.=meth
+
+The C<.=> operator does inplace modification of the object on the left.
+
+=item *
+
+Meta-method call
+
+ $obj.^meth
+
+The C<.^> operator calls a class metamethod;
+C<foo.^bar> is short for C<foo.HOW.bar>.
+
+=item *
+
+Method-like postcircumfixes
+
+ $routine.()
+ $array.[]
+ $hash.{}
+ $hash.<>
+ $hash.«»
+
+The dotless forms of these have exactly the same precedences.
+
+=item *
+
+Dotted form of any other postfix operator
+
+ $x.++ # postfix:<++>($x)
+
+=item *
+
+Dotted postfix form of any other prefix operator
+
+ $x.'++' # prefix:<++>($x), fallback to postfix:<++>
+
+=back
+
+=head2 Autoincrement precedence
+
+As in C, these operators increment or decrement the object in question
+either before or after the value is taken from the object, depending on
+whether it is put before or after. Also as in C, use of multiple side
+effects on a single object in the same expression results in undefined
+behavior unless some explicit sequencing operator is interposed.
+
+As with all postfix operators in Perl 6, no space is allowed between
+a term and its postfix. See S02 for why, and for how to work around the
+restriction with a "long dot".
+
+=over
+
+=item *
+
+Autoincrement prefix:<++> or postfix:<++> operator
+
+ $x++
+ ++$x;
+
+=item *
+
+Autodecrement prefix:<--> or postfix:<--> operator
+
+ $x--
+ --$x
+
+=back
+
+=head2 Exponentiation precedence
+
+=over
+
+=item *
+
+infix:<**> exponentiation operator
+
+ $x ** 2
+
+If the right argument is not an integer, the result is likely to
+be an approximation. If the right argument is of an integer type,
+exponentiation is at least as accurate as repeated multiplication on
+the left side's type. (From which it can be deduced that C<Int**Int>
+is always exact, since Int supports arbitrary precision.) If the
+right argument is an integer represented in a non-integer type, the
+accuracy is left to implementation provided by that type; there is
+no requirement to recognize an integer to give it special treatment.
+
+=back
+
+=head2 Symbolic unary precedence
+
+=over
+
+=item *
+
+prefix:<?>, boolean context
+
+ ?
+
+See "true" below for a low-precedence alternative.
+
+=item *
+
+prefix:<!>, boolean negation
+
+ !
+
+See "not" below for a low-precedence alternative.
+
+=item *
+
+prefix:<+>, numeric context
+
+ +
+
+=item *
+
+prefix:<->, numeric negation
+
+ -
+
+=item *
+
+prefix:<~>, string context
+
+ ~
+
+=item *
+
+prefix:<|>, flatten object into arglist
+
+ |
+
+=item *
+
+prefix:<+^>, numeric bitwise negation
+
+ +^
+
+=item *
+
+prefix:<~^>, string bitwise negation
+
+ ~^
+
+=item *
+
+prefix:<?^>, boolean bitwise negation
+
+ ?^
+
+=item *
+
+prefix:<\>, Capture constructor
+
+ \
+
+=item *
+
+prefix:<^>, upto operator
+
+ ^
+
+Constructs a range or locates a metaclass. See L</Range semantics>.
+
+=item *
+
+prefix:<=>, iterate iterator
+
+ =
+
+Unary C<=> reads lines from a filehandle or filename, or
+iterates an iterator, or in general causes a scalar to explode its guts
+when it would otherwise not. How it does that is context sensitive.
+For instance, C<=$iterator> is scalar/list sensitive and will
+produce one value in scalar context but many values in list context.
+(Use C<@$iterator> to force a fetch of all the values even in scalar
+context, and C<$$iterator> to force a fetch of a single value even
+in list context.) On the other hand, C<=$capture> interpolates all
+parts of the capture that makes sense in the current list context,
+depending on what controls that list context.
+
+=back
+
+=head2 Multiplicative precedence
+
+=over
+
+=item *
+
+infix:<*>
+
+ *
+
+=item *
+
+infix:</>
+
+ $dividend / $divisor
+
+Converts both operands to Num and does division returning Num.
+
+=item *
+
+infix:<div>
+
+ $dividend div $divisor
+
+Dispatches to the infix:<div> multi most appropriate to the operand types.
+
+=item *
+
+infix:<%>, modulus
+
+ %
+
+=item *
+
+infix:<x>, string replication
+
+ x
+
+=item *
+
+infix:<xx>, list replication
+
+ xx
+
+=item *
+
+infix:{'+&'}, numeric bitwise and
+
+ +&
+
+=item *
+
+infix:{'+<'}, numeric shift left
+
+ +<
+
+=item *
+
+infix:{'+<'}, numeric shift right
+
+ +>
+
+=item *
+
+infix:<~&>, string bitwise and
+
+ ~&
+
+=item *
+
+infix:{'~<'}, string bitwise shift left
+
+ ~<
+
+=item *
+
+infix:{'~>'}, string bitwise shift right
+
+ ~>
+
+=item *
+
+infix:<?&>, boolean bitwise and
+
+ ?&
+
+=item *
+
+infix:<div>, generic division
+
+ div
+
+=item *
+
+infix:<mod>, generic modulus
+
+ mod
+
+=back
+
+=head2 Additive precedence
+
+=over
+
+=item *
+
+infix:<+>, numeric addition
+
+ +
+
+=item *
+
+infix:<->, numeric subtraction
+
+ -
+
+=item *
+
+infix:<~>, string concatenation
+
+ ~
+
+=item *
+
+infix:<+|>, numeric bitwise inclusive or
+
+ +|
+
+=item *
+
+infix:<+^> numeric bitwise exclusive or
+
+ +^
+
+=item *
+
+infix:<~|>, string bitwise inclusive or
+
+ ~|
+
+=item *
+
+infix:<~^> string bitwise exclusive or
+
+ ~^
+
+=item *
+
+infix:<?|>, boolean bitwise inclusive or
+
+ ?|
+
+=item *
+
+infix:<?^> boolean bitwise exclusive or
+
+ ?^
+
+=back
+
+=head2 Junctive and (all) precedence
+
+=over
+
+=item *
+
+infix:<&>, all() operator
+
+ &
+
+=back
+
+=head2 Junctive or (any) precedence
+
+=over
+
+=item *
+
+infix:<|>, any() operator
+
+ |
+
+=item *
+
+infix:<^>, one() operator
+
+ ^
+
+=back
+
+=head2 Named unary precedence
+
+=over
+
+=item *
+
+Functions of one argument
+
+ rand sleep abs etc.
+
+Note that, unlike in Perl 5, you must use the C<.meth> forms to default
+to C<$_> in Perl 6.
+
+=item *
+
+File test operators
+
+ -e -r -w -x etc.
+
+=item *
+
+The C<item> contextualizer
+
+ item
+
+The new name for Perl 5's C<scalar> contextualizer. Equivalent to C<$()>.
+
+=back
+
+=head2 Nonchaining binary precedence
+
+=over
+
+=item *
+
+infix:<but>
+
+ but
+
+=item *
+
+infix:<does>
+
+ does
+
+=item *
+
+Sort comparisons
+
+ $num1 <=> $num2
+ $str1 leg $str2
+ $obj1 cmp $obj2
+
+These operators compare their operands using numeric, string,
+or C<eqv> semantics respectively, and depending on the order return
+one of C<Order::Increase>, C<Order::Same>, or C<Order::Decrease>
+(which numerify to -1, 0, or +1). See L</Comparion semantics>.
+
+=item *
+
+Range object constructor
+
+ $min .. $max
+ $min ^.. $max
+ $min ..^ $max
+ $min ^..^ $max
+
+Constructs Range objects, optionally excluding one or both endpoints.
+See L</Range semantics>.
+
+=item *
+
+Flipflop ranges
+
+ start() ff end()
+ start() ^ff end()
+ start() ff^ end()
+ start() ^ff^ end()
+
+=item *
+
+Flipflop ranges (sed style)
+
+ start() fff end()
+ start() ^fff end()
+ start() fff^ end()
+ start() ^fff^ end()
+
+=back
+
+=head2 Chaining binary precedence
+
+All operators on this precedence level may be I<chained>; see
+L</Chained comparisons>.
+
+=over
+
+=item *
+
+infix:<==> etc.
+
+ == != < <= > >=
+
+As in Perl 5, converts to Num before comparison. C<!=> is short for C<!==>.
+
+=item *
+
+infix:<eq> etc.
+
+ eq ne lt le gt ge
+
+As in Perl 5, converts to Str before comparison. C<ne> is short for C<!eq>.
+
+=item *
+
+Generic ordering
+
+ $a before $b
+ $a after $b
+
+=item *
+
+Smart match
+
+ ~~
+
+Perl 5's C<=~> becomes the "smart match" operator C<~~>, with an
+extended set of semantics. See L</Smart matching> for details.
+
+To catch "brainos", the Perl 6 parser defines an C<< infix:<=~> >>
+operator which always fails at compile time with a message directing
+the user to use C<~~> or C<~=> (string append) instead if they meant
+it as a single operator, or to put a space between if they really
+wanted to assign a stringified value as two separate operators.
+
+A negated smart match is spelled C<!~~>.
+
+=item *
+
+Container identity
+
+ VAR($a) =:= VAR($b)
+
+See L</Comparison semantics>.
+
+=item *
+
+Value identity
+
+ $x === $y
+
+For objects that are not value types, their identities are their values.
+(Identity is returned by the C<.WHICH> metamethod.) The actual contents of
+the objects are ignored. These semantics are those used by hashes that
+allow objects for keys. See also L</Comparison semantics>.
+
+=item *
+
+Canonical equivalence
+
+ $obj1 eqv $obj2
+
+Compares two objects for canonical equivalence. For value types compares
+the values. For object types, compares current contents according to some
+scheme of canonicalization. These semantics are those used by hashes
+that allow only values for keys (such as Perl 5 string-key hashes).
+See also L</Comparison semantics>.
+
+=item *
+
+Negated relational operators
+
+ $num !== 42
+ $str !eq "abc"
+ "foo" !~~ /^ <ident> $/
+ VAR($a) !=:= VAR($b)
+ $a !=== $b
+ $a !eqv $b
+
+See L</Negated relational operators>.
+
+=back
+
+=head2 Tight and precedence
+
+=over
+
+=item *
+
+infix:<&&>, short-circuit and
+
+ &&
+
+Returns the left argument if the left argument is false, otherwise returns
+the right argument. In list context forces a false return to mean C<()>.
+See C<and> below for low-precedence version.
+
+=back
+
+=head2 Tight or precedence
+
+=over
+
+=item *
+
+infix:<||>, short-circuiting inclusive-or
+
+ ||
+
+Returns the left argument if it's true, otherwise the right argument.
+In list context forces a false return to mean C<()>.
+See C<or> below for low-precedence version.
+
+=item *
+
+infix:<^^>, exclusive-or
+
+ ^^
+
+Returns the true argument if there is one (and only one). Returns
+C<Bool::False> if both arguments are false or both arguments are true.
+In list context forces a false return to mean C<()>.
+See C<xor> below for low-precedence version.
+
+=item *
+
+infix:<//>, defined-or
+
+ //
+
+Returns the left argument if it's defined, otherwise the right argument.
+In list context forces a false return to mean C<()>.
+See C<err> below for low-precedence version.
+
+=item *
+
+Minimum and maximum
+
+ $min0 min $min1
+ $max0 max $max1
+
+Instead of deciding whether to return the left or right based on booleans
+or definedness, these return the minimum or maximum value. See also the
+minmax listop.
+
+=back
+
+=head2 Conditional precedence
+
+=over
+
+=item *
+
+?? !!
+
+ say "My answer is: ", $maybe ?? "yes" !! "no";
+
+It is a syntax error to use an
+operator in the middle that binds looser in precedence, such as C<=>.
+
+=back
+
+=head2 Item assignment precedence
+
+=over
+
+=item *
+
+infix:<=>
+
+ $x = 1, $y = 2;
+
+With simple lvalues, C<=> has this precedence, which is tighter than comma.
+(List assignments have listop precedence below.)
+
+=item *
+
+infix:<:=>, run-time binding
+
+ :=
+
+A new form of assignment is present in Perl 6, called I<binding>, used in
+place of typeglob assignment. It is performed with the C<:=> operator.
+Instead of replacing the value in a container like normal assignment, it
+replaces the container itself. For instance:
+
+ my $x = 'Just Another';
+ my $y := $x;
+ $y = 'Perl Hacker';
+
+After this, both C<$x> and C<$y> contain the string C<"Perl Hacker">,
+since they are really just two different names for the same variable.
+
+There is also an identity test, C<=:=>, which tests whether two names
+are bound to the same underlying variable. C<$x =:= $y> would return
+true in the above example.
+
+The binding fails if the type of the variable being bound is sufficiently
+inconsistent with the type of the current declaration.
+
+=item *
+
+infix:<::=>, compile-time binding
+
+ ::=
+
+This does the same as C<:=> except it does it at compile time.
+
+=item *
+
+infix:{'=>'}, Pair constructor
+
+ foo => 1, bar => "baz"
+
+Binary C<< => >> is no longer just a "fancy comma". It now constructs
+a C<Pair> object that can, among other things, be used to pass named
+arguments to functions. It provides scalar context to both sides.
+It does not actually do an assignment except in a notional sense;
+however its precedence is now equivalent to assignment, and it is
+also right associative. Note that, unlike in Perl 5, C<< => >>
+binds tighter than comma.
+
+=item *
+
+Assignment operators
+
+ += -= **= xx= .= etc.
+
+See L</Assignment operators>.
+
+=back
+
+=head2 Loose unary precedence
+
+=over
+
+=item *
+
+prefix:<true>
+
+ true any(@args) eq '-v' | '-V'
+
+=item *
+
+prefix:<not>
+
+ not any(@args) eq '-v' | '-V'
+
+=back
+
+=head2 List ops precedence
+
+=over
+
+=item *
+
+infix:<=>, list assignment
+
+ @array = 1,2,3;
+
+With compound targets, performs list assignment. The right side is looser
+than comma. You can view the left side as a special syntax for a prefix
+listop, much as if you'd said:
+
+ @array.assign: 1,2,3
+
+=item *
+
+infix:<,>, the argument separator
+
+ 1, 2, 3, @many
+
+Unlike in Perl 5, comma operator never returns the last value. (In item
+context it returns a list instead.)
+
+=item *
+
+infix:<:>, the invocant marker
+
+ say $*OUT: "howdy, world"
+
+The colon that turns a method call into a list operator also sits
+in the "comma" slot. It cannot be used just anywhere though.
+Much like list assignment, it takes a special syntax on the left
+side and turns it into a list operator over the list on the right.
+See L</Invocant marker>.
+
+Comma, C<=>, and C<:> are the only listops that are allowed to occur
+where an infix is expected. All other listops function as a term
+within the expression to the left.
+
+=item *
+
+Normal listops
+
+ print push say join split substr open etc.
+
+=item *
+
+Listop forms of junctional operators
+
+ any all one none
+
+=item *
+
+Exception generators
+
+ fail "Division by zero"
+ die System::Error(ENOSPC,"Drive $d seems to be full");
+ warn "Can't open file: $!"
+
+=item *
+
+Stubby exception generators
+
+ ...
+ !!! "fill this in later, Dave"
+ ??? "oops in $?CLASS"
+
+The C<...> operator is the "yada, yada, yada" list operator, which
+among other things is used as the body in function prototypes.
+It complains bitterly (by calling C<fail>) if it is ever executed.
+Variant C<???> calls C<warn>, and C<!!!> calls C<die>. The argument
+is optional, but if provided, is passed onto the C<fail>, C<warn>,
+or C<die>. Otherwise the system will make up a message for you based
+on the context, indicating that you tried to execute something that
+is stubbed out. (This message differs from what C<fail>, C<warn>, and
+C<die> would say by default, since the latter operators typically point
+out bad data or programming rather than just an incomplete design.)
+
+=item *
+
+Reduce operators
+
+ [+] [*] [<] [\+] [\*] etc.
+
+See L<Reduction operators>.
+
+=item *
+
+The C<list> contextualizer
+
+ list
+
+Forces the subsequent expression to be evaluated in list context.
+Equivalent to C<@()>.
+
+=back
+
+=head2 List infix precedence
+
+=over
+
+=item *
+
+infix:<¥>, the zip operator
+
+ 1,2 ¥ 3,4 # (1,3),(2,4)
+
+=item *
+
+infix:{'<=='}, the feed-left operator
+
+ target <== @list
+
+See L</Feed operators>.
+
+=item *
+
+infix:{'==>'}, the feed-right operator
+
+ @list ==> target
+
+See L</Feed operators>.
+
+=item *
+
+The minmax operator
+
+ $min0, $max0 minmax $min1, $max1 # ($min0 min $min1, $max0 max $max1)
+
+=item *
+
+List and string cross operators
+
+ 1,2 XX 3,4 # (1,3), (1,4), (2,3), (2,4)
+ 1,2 X 3,4 # '13', '14', '23', '24'
+
+In contrast to the zip operator, the C<XX> operator returns all the
+permutations of its sublists. Hence you may say:
+
+ <a b> XX <1 2>
+
+and you end up with
+
+ ('a', '1'), ('a', '2'), ('b', '1'), ('b', '2')
+
+The C<X> variant crosses the arrays but concatenates strings:
+
+ <a b> X <1 2>
+
+produces
+
+ 'a1', 'a2', 'b1', 'b2'
+
+The resemblance to C<x> and C<xx> is not entirely accidental.
+
+=item *
+
+Cross hyperoperators
+
+ X~X
+ X*X
+ XeqvX
+ etc.
+
+See L</Cross operators>.
+
+=item *
+
+Sigils as contextualizer listops
+
+ $:
+ @:
+ %:
+ &:
+ @@:
+
+Like listops, these look like terms from the left, but raise their
+precedence on the right sufficiently to govern the list infix
+operators above:
+
+ $: 1,2 ¥ 3,4 # [1,3,2,4]
+ @: 1,2 ¥ 3,4 # 1,3,2,4
+ @@: 1,2 ¥ 3,4 # [1,3],[2,4]
+ %: 1,2 ¥ 3,4 # { 1 => 3, 2 => 4 }
+
+ $: 1,2 XX 3,4 # [1,3,1,4,2,3,2,4]
+ @: 1,2 XX 3,4 # 1,3,1,4,2,3,2,4
+ @@: 1,2 XX 3,4 # [1,3],[1,4],[2,3],[2,4]
+
+These can also influence the result of functions that returns lists of captures:
+
+ $: map { $_, $_*2 }, ^4 # [0,0,1,2,2,4,3,6]
+ @: map { $_, $_*2 }, ^4 # 0,0,1,2,2,4,3,6
+ @@: map { $_, $_*2 }, ^4 # [0,0],[1,2],[2,4],[3,6]
+ %: map { $_, $_*2 }, ^4 # { 0 => 0, 1 => 2, 2 => 4, 3 => 6 }
+
+=back
+
+=head2 Loose and precedence
+
+=over
+
+=item *
+
+infix:<and>
+
+ and
+
+Returns the left argument if the left argument is false, otherwise returns
+the right argument. In list context forces a false return to mean C<()>.
+See C<&&> above for high-precedence version.
+
+=back
+
+=head2 Loose or precedence
+
+=over
+
+=item *
+
+infix:<or>
+
+ or
+
+Returns the left argument if it's true, otherwise the right argument.
+In list context forces a false return to mean C<()>.
+See C<||> above for high-precedence version.
+
+=item *
+
+infix:<xor>
+
+ xor
+
+Returns the true argument if there is one (and only one). Returns
+C<Bool::False> if both arguments are false or both arguments are true.
+In list context forces a false return to mean C<()>.
+See C<^^> above for high-precedence version.
+
+=item *
+
+infix:<err>
+
+ err
+
+Returns the left argument if it's defined, otherwise the right argument.
+In list context forces a false return to mean C<()>.
+See C<//> above for high-precedence version.
+
+=back
+
+=head2 Terminator precedence
+
+As with terms, terminators are not really a precedence level, but looser
+than the loosest precedence level. They all have the effect of terminating
+any operator precedence parsing and returning a complete expression to the main
+parser.
+
+=over
+
+=item *
+
+infix:<;>
+
+ $x = 1; $y = 2;
+
+=item *
+
+{} as control block
+
+When a block occurs after whitespace where an infix is expected, it is
+interpreated as a control block for a statement control construct.
+(If there is no whitespace, it is a subscript, and if it is where a
+term is expected, it's just a bare closure.) If there is no statement
+looking for such a block currently, it is a syntax error.
+
+=item *
+
+Statement modifiers terminate one expression and start another.
+
+=item *
+
+Unmatched ), ], }, etc.
+
+Calls into the operator precedence parser may be parameterized
+to recognize additional terminators, but right brackets of any
+sort (except angles) are automatically included in the set of
+terminators as tokens of length one. (An infix of longer length
+could conceivably start with one of these characters, and would be
+recognized under the longest-token rule and continue the expression,
+but this practice is discouraged. It would be better to use Unicode
+for your weird operator.) Angle brackets are exempted so that they
+can form hyperoperators (see L</Hyper operators>).
+
+=back

=head1 Changes to Perl 5 operators

Several operators have been given new names to increase clarity and better
-Huffman-code the language, while others have changed precedence. (If an
-operator is not mentioned in this Synopsis, assume that it remains the
-same as in Perl 5. And if that doesn't make sense, assume this document
-is faulty. :)
+Huffman-code the language, while others have changed precedence.

=over

-=item * Perl 5's C<${...}>, C<@{...}>, C<%{...}>, etc. dereferencing
+=item *
+
+Perl 5's C<${...}>, C<@{...}>, C<%{...}>, etc. dereferencing
forms are now C<$(...)>, C<@(...)>, C<%(...)>, etc. instead.
+Listop-like forms are C<$:>, C<@:>, C<%:>, etc.
+
+=item *
+
+C<< -> >> becomes C<.>, like the rest of the world uses.

-=item * C<< -> >> becomes C<.>, like the rest of the world uses.
+=item *

-=item * The string concatenation C<.> becomes C<~>. Think of it as
+The string concatenation C<.> becomes C<~>. Think of it as
"stitching" the two ends of its arguments together. String append
is likewise C<~=>.

-=item * The filetest operators now return a result that is both a
+=item *
+
+The filetest operators now return a result that is both a
boolean (or in the case of C<-s>, a number) and a stat buffer, so
there is no longer any need for Perl 5's C<_> term. Instead just
cascade tests to "and" them:
@@ -49,7 +1311,9 @@
if -w $sb {...}
if -x $sb {...}

-=item * All postfix operators that do not start with a dot also have
+=item *
+
+All postfix operators that do not start with a dot also have
an alternate form that does. (The converse does not hold--just because
you can write C<x().foo> doesn't mean you can write C<x()foo>. Likewise
the ability to say C<$x.'foo'> does not imply that C<$x'foo'> will work.)
@@ -61,7 +1325,9 @@
C<$filename.'-e'.'-r'>. You may even say things like C<$fh.'='>, which
because of the quotes will not be confused lexically with C<$fh.=new>.

-=item * Unary C<~> now imposes a string (C<Str>) context on its
+=item *
+
+Unary C<~> now imposes a string (C<Str>) context on its
argument, and C<+> imposes a numeric (C<Num>) context (as opposed
to being a no-op in Perl 5). Along the same lines, C<?> imposes
a boolean (C<Bool>) context, and the C<|> unary operator imposes
@@ -70,7 +1336,9 @@
As with Perl 5, however, C<$$foo[bar]> parses as C<( $($foo) )[bar]>,
so you need C<$($foo[bar])> to mean the other way.

-=item * Bitwise operators get a data type prefix: C<+>, C<~>, or C<?>.
+=item *
+
+Bitwise operators get a data type prefix: C<+>, C<~>, or C<?>.
For example, Perl 5's C<|> becomes either C<+|> or C<~|> or C<?|>,
depending on whether the operands are to be treated as numbers,
strings, or boolean values. Perl 5's left shift C< << > becomes
@@ -97,25 +1365,34 @@
the string to a number first on the assumption that the string was an
ASCII representation of a number.

-=item * C<x> splits into two operators: C<x> (which concatenates repetitions
+=item *
+
+C<x> splits into two operators: C<x> (which concatenates repetitions
of a string to produce a single string), and C<xx> (which creates a list of
repetitions of a list or scalar). C<"foo" xx *> represents an arbitrary
number of copies, useful for initializing lists. The left side of
an C<xx> is evaluated only once. (To call a block repeatedly, use a C<map>
instead.)

-=item * The C<? :> conditional operator becomes C<?? !!>. It is a syntax error to use an
-operator in the middle that binds looser in precedence, such as C<=>.
+=item *
+
+The C<? :> conditional operator becomes C<?? !!>.
+
+=item *

-=item * C<qw{ ... }> gets a synonym: C< < ... > >, and an interpolating
+C<qw{ ... }> gets a synonym: C< < ... > >, and an interpolating
variant, C<«...»>.
For those still living without the blessings of Unicode, that can also be
written: C<<< << ... >> >>>.

-=item * The scalar comma C<,> now constructs a C<List> object from its
+=item *
+
+The scalar comma C<,> now constructs a C<List> object from its
operands. You have to use a C<[-1]> subscript to get the last one.

-=item * The unary backslash operator captures its arguments, and returns an
+=item *
+
+The unary backslash operator captures its arguments, and returns an
object representing those arguments. You can I<dereference> this object
in several ways to retrieve different parts of the arguments; see the
definition of C<Capture> in S02 for details. (No whitespace is allowed
@@ -124,7 +1401,9 @@
However, oddly enough, because of that unspace rule, saying C<\\ $foo>
turns out to be equivalent to C<\$foo>.)

-=item * The old scalar C<..> flipflop operator is now done with
+=item *
+
+The old scalar C<..> flipflop operator is now done with
C<ff> operator. (C<..> now always produces a C<Range> object
even in scalar context.) The C<ff> operator may take a caret on
either end to exclude either the beginning or ending. There is
@@ -135,10 +1414,14 @@

to indicate a flipflop that never flops once flipped.

-=item * All comparison operators are unified at the same precedence level.
-See Chained Comparisons below.
+=item *
+
+All comparison operators are unified at the same precedence level.
+See L</Chained comparisons> below.

-=item * The list assignment operator now parses on the right like
+=item *
+
+The list assignment operator now parses on the right like
any other list operator, so you don't need parens on the right side of:

@foo = 1,2,3;
@@ -149,7 +1432,9 @@

since assignment operators are tighter than comma to their left.

-=item * The scalar assignment operator still parses as it did before, so
+=item *
+
+The scalar assignment operator still parses as it did before, so

loop ($a = 1, $b = 2; ; $a++, $b++) {...}

@@ -262,7 +1547,9 @@
The rest of the time scalar or list behavior can be forced with minimal
syntax.

-=item * List operators are all parsed consistently. As in Perl 5,
+=item *
+
+List operators are all parsed consistently. As in Perl 5,
to the left a list operator look like term, while to the right it looks like
an operator that is looser than comma. Unlike in Perl 5, the difference
between the list operator form and the function form is consistently
@@ -352,26 +1639,34 @@
whitespace dependency in order to gain a completely extensible class
of postfix operators.

-=item * A list operator's arguments are also terminated by a closure
+=item *
+
+A list operator's arguments are also terminated by a closure
that is not followed by a comma or colon. (And a semicolon is implied
if the closure is the final thing on a line. Use an "unspace" to
suppress that.) This final closure may be followed by a postfix,
in which case the postfix is applied to the result of the entire
list operator.

-=item * A function predeclared as 0-ary is never considered list
+=item *
+
+A function predeclared as 0-ary is never considered list
operator, though it allows an optional set of empty parentheses.
Unlike functions and list operators with arguments (see above),
a 0-ary function does not require parentheses even if followed
immediately by a postfix.

-=item * A non-multi sub predeclared with an arity of exactly 1 parses
+=item *
+
+A non-multi sub predeclared with an arity of exactly 1 parses
as a named unary in precedence. All other subs with arguments
parse as list operators. (In other words, a named unary operator
may be declared to take extra arguments only if they are named-only
arguments.)

-=item * The C<&&> and C<||> operators are smarter about list context
+=item *
+
+The C<&&> and C<||> operators are smarter about list context
and return C<()> on failure in list context rather than C<Bool::False>.
The operators still short-circuit, but if either operator would return
a false value, it is converted to the null list in list context so
@@ -386,15 +1681,75 @@

=back

-=head1 New operators
+=head1 Junctive operators
+
+C<|>, C<&>, and C<^> are no longer bitwise operators (see
+L</Changes to Perl 5 operators>) but now serve a much higher cause:
+they are now the junction constructors.
+
+A junction is a single value that is equivalent to multiple values. They
+thread through operations, returning another junction representing the
+result:
+
+ (1|2|3) + 4; # 5|6|7
+ (1|2) + (3&4); # (4|5) & (5|6)
+
+Note how when two junctions are applied through an operator, the result
+is a junction representing the operator applied to each combination of
+values.
+
+Junctions come with the functional variants C<any>, C<all>, C<one>, and C<none>.
+
+This opens doors for constructions like:
+
+ unless $roll == any(1..6) { print "Invalid roll" }
+
+ if $roll == 1|2|3 { print "Low roll" }
+
+Junctions work through subscripting:
+
+ doit() if @foo[any(1,2,3)]
+
+Junctions are specifically unordered. So if you say
+
+ for all(@foo) {...}
+
+it indicates to the compiler that there is no coupling between loop
+iterations and they can be run in any order or even in parallel. XXX bogus
+
+Use of negative operators with syntactically recognizable junctions may
+produce a warning on code that works differently in English than in Perl.
+Instead of writing
+
+ if $a != 1 | 2 | 3 {...}
+
+you need to write
+
+ if not $a == 1 | 2 | 3 {...}
+
+However, this is only a syntactic warning, and
+
+ if $a != $b {...}
+
+will not complain if $b happens to contain a junction at runtime.
+
+Junctive methods on arrays, lists, and sets work just like the
+corresponding list operators. However, junctive methods on a hash
+make a junction of only the hash's keys. Use the listop form (or an
+explicit C<.pairs>) to make a junction of pairs.
+
+=head1 Comparison semantics

=over

-=item * Binary C<//> is just like C<||>, except that it tests its left
-side for definedness instead of truth. There is a low-precedence form,
-too: C<err>.
+=item *

-=item * Binary C<===> tests immutable type and value correspondence:
+Perl 5's comparison operators are basically unchanged, except that they
+can be chained because their precedence is unified.
+
+=item *
+
+Binary C<===> tests immutable type and value correspondence:
for two value types (that is, immutable types), tests whether
they are the same value (eg. C<1 === 1>); for two mutable types
(object types), checks whether they have the same identity value.
@@ -415,10 +1770,13 @@
numeric. In fact, C<$a eq $b> really means "C<~$a === ~$b>" and C<$a == $b>
means C<+$a === +$b>.

-Note also that, while string hashes use C<eq> semantics by default,
-object hashes use C<===> semantics.
+Note also that, while string-keyed hashes use C<eq> semantics by default,
+object-keyed hashes use C<===> semantics, and general value-keyed hashes
+use C<eqv> semantics.

-=item * Binary C<eqv> tests equality much like C<===> does, but does
+=item *
+
+Binary C<eqv> tests equality much like C<===> does, but does
so with "snapshot" semantics rather than "eternal" semantics. For
top-level components of your value that are of immutable types, C<eqv>
is identical in behavior to C<===>. For components of your value
@@ -442,52 +1800,48 @@
and traits. If the signature doesn't match the operands, C<eqv()>
reverts to standard C<eqv> comparison. (Likewise for C<cmp()>.)

-=item * Binary C<cmp> is no longer the comparison operator that
+=item *
+
+Binary C<cmp> is no longer the comparison operator that
forces stringification. Use the C<leg> operator for the old Perl 5
C<cmp> semantics. The C<cmp> is just like the C<eqv> above except that
instead of returning C<Bool::False> or C<Bool::True> values it always
returns C<Order::Increase>, C<Order::Same>, or C<Order::Decrease>
(which numerify to -1, 0, or +1).

-=item * The C<leg> operator (less than, equal, or greater) is defined
+=item *
+
+The C<leg> operator (less than, equal, or greater) is defined
in terms of C<cmp>, so C<$a leg $b> is now defined as C<~$a cmp ~$b>.
The sort operator still defaults to C<cmp> rather than C<leg>. The
C<< <=> >> operator's semantics are unchanged except that it returns
an C<Order> value as described above. In other words, C<< $a <=> $b >>
is now equivalent to C<+$a cmp +$b>.

-=item * For boolean comparison operators with non-coercive C<cmp>
+=item *
+
+For boolean comparison operators with non-coercive C<cmp>
semantics, use the generic C<before> and C<after> infix operators.
As ordinary infix operators these may be negated (C<!before> and C<!after>)
as well as reduced (C<[before]> and C<[after]>).

-=item * Infix C<min> and C<max> may be used to select one or the other
+=item *
+
+Infix C<min> and C<max> may be used to select one or the other
of their arguments. Reducing listop forms C<[min]> and C<[max]> are
also available, as are the C<min=> and C<max=> assignment operators.
By default C<min> and C<max> use C<cmp> semantics. As with all C<cmp>-based
operators, this may be modified by an adverb specifying different semantics.

-=item * Binary C<< => >> is no longer just a "fancy comma". It now
-constructs a C<Pair> object that can, among other things, be used to
-pass named arguments to functions. It provides scalar context to both sides.
-Its precedence is now equivalent to assignment, and it is right associative.
-
-=item * C<^^> is the high-precedence version of C<xor>.
-
-=item * C<=~> becomes the "smart match" operator C<~~>, with a whole new set
-of semantics. Anywhere you used C<=~> before you now use C<~~>, but C<~~>
-is much more general now. See "Smart matching" below for details. (To catch
-"brainos", the Perl 6 parser defines an C<< infix:<=~> >> macro which always
-fails at compile time with a message directing the user either to use C<~~>
-or C<~=> (string append) instead, or to put a space between if they
-really wanted to assign a stringified value.) A negated smart match is
-spelled C<!~~>.
-
-=item * "Unary" C<.> calls its single argument (which must be a postfix
-operator) on C<$_>. (It's not really a unary operator, so we put it in
-quotes.)
+=back
+
+=head1 Range semantics
+
+=over
+
+=item *

-=item * The C<..> range operator has variants with C<^> on either
+The C<..> range operator has variants with C<^> on either
end to indicate exclusion of that endpoint from the range. It always
produces a C<Range> object. Range objects are lazy iterators, and can
be interrogated for their current C<.min> and C<.max> values (which
@@ -535,7 +1889,9 @@

@array[0..^@array], @array[-1] xx *

-=item * The unary C<^> operator generates a range from C<0> up to
+=item *
+
+The unary C<^> operator generates a range from C<0> up to
one less than its argument. So C<^4> is short for C<0..^4> or C<0..3>.

for ^4 { say $_ } # 0, 1, 2, 3
@@ -548,7 +1904,9 @@
so C<^Moose> is short for C<HOW(Moose)> or C<Moose.HOW>. It still kinda
means "what is this thing's domain" in an abstract sort of way.

-=item * Since use of C<Range> objects in scalar context is usually
+=item *
+
+Since use of C<Range> objects in scalar context is usually
non-sensical, a C<Range> object used as an operand for scalar operators
will generally attempt to distribute the operator to its endpoints and
return another suitably modified C<Range> instead. (Notable exceptions
@@ -577,35 +1935,29 @@
Conjecture: non-linear functions might even produce non-uniform "by" values!
Think of log scaling, for instance.

-=item * The C<...> operator is the "yada, yada, yada" list operator,
-which is used as the body in function prototypes. It complains
-bitterly (by calling C<fail>) if it is ever executed. Variant C<???>
-calls C<warn>, and C<!!!> calls C<die>. The argument is optional,
-but if provided, is passed onto the C<fail>, C<warn>, or C<die>.
-Otherwise the system will make up a message for you based on the
-context, indicating that you tried to execute something that is
-stubbed out. (This message differs from what C<fail>, C<warn>, and
-C<die> would say by default, since the latter operators typically point
-out bad data or programming rather than just an incomplete design.)
+=back
+
+=head1 Chained comparisons
+
+Perl 6 supports the natural extension to the comparison operators,
+allowing multiple operands:
+
+ if 1 < $a < 100 { say "Good, you picked a number *between* 1 and 100." }
+
+ if 3 < $roll <= 6 { print "High roll" }
+
+ if 1 <= $roll1 == $roll2 <= 6 { print "Doubles!" }
+
+A chain of comparisons short-circuits if the first comparison fails:
+
+ 1 > 2 > die("this is never reached");

-=item * In addition to the ordinary C<.> method invocation, there are
-variants C<.*>, C<.?>, and C<.+> to control how multiple related methods
-of the same name are handled. The C<.=> operator does inplace modification
-of the object on the left. The C<.^> operator calls a class metamethod;
-C<foo.^bar> is short for C<foo.HOW.bar>.
+Each argument in the chain will evaluate at most once:

-=item * Unary C<=> reads lines from a filehandle or filename, or
-iterates an iterator, or in general causes a scalar to explode its guts
-when it would otherwise not. How it does that is context sensitive.
-For instance, C<=$iterator> is scalar/list sensitive and will
-produce one value in scalar context but many values in list context.
-(Use C<@$iterator> to force a fetch of all the values even in scalar
-context, and C<$$iterator> to force a fetch of a single value even
-in list context.) On the other hand, C<=$capture> interpolates all
-parts of the capture that makes sense in the current list context,
-depending on what controls that list context.
+ 1 > $x++ > 2 # $x increments exactly once

-=back
+Note: any operator beginning with C<< < >> must have whitespace
+in front of it, or it will be interpreted as a hash subscript instead.

=head1 Smart matching

@@ -694,30 +2046,30 @@

All smartmatch types are scalarized; both C<~~> and C<given>/C<when>
provide scalar contexts to their arguments, and autothread any
-junctive matches so that the eventual dispatch to C<.accepts> never
+junctive matches so that the eventual dispatch to C<.ACCEPTS> never
sees anything "plural". So both C<$_> and C<X> above are potentially
container objects that are treated as scalars. (You may hyperize
C<~~> explicitly, though. In this case all smartmatching is done
-using the type-based dispatch to C<.accepts>, not the form-based
+using the type-based dispatch to C<.ACCEPTS>, not the form-based
dispatch at the front of the table.)

The exact form of the underlying type-based method dispatch is:

- X.accepts($_) # for ~~
- X.rejects($_) # for !~~
+ X.ACCEPTS($_) # for ~~
+ X.REJECTS($_) # for !~~

As a single dispatch call this pays attention only to the type of
-C<X> initially. The C<accepts> method interface is defined by the
+C<X> initially. The C<ACCEPTS> method interface is defined by the
C<Pattern> role. Any class composing the C<Pattern> role may choose
-to provide a single C<accepts> method to handle everything, which
+to provide a single C<ACCEPTS> method to handle everything, which
corresponds to those pattern types that have only one entry with
an C<Any> on the left above. Or the class may choose to provide
-multiple C<accepts> multi-methods within the class, and these
+multiple C<ACCEPTS> multi-methods within the class, and these
will then redispatch within the class based on the type of C<$_>.
-The class may also define one or more C<rejects> methods; if it does
-not, the default C<rejects> method from the C<Pattern> role defines
-it in terms of a negated C<accepts> method call. This generic method
-may be less efficient than a custom C<rejects> method would be, however.
+The class may also define one or more C<REJECTS> methods; if it does
+not, the default C<REJECTS> method from the C<Pattern> role defines
+it in terms of a negated C<ACCEPTS> method call. This generic method
+may be less efficient than a custom C<REJECTS> method would be, however.

The smartmatch table is primarily intended to reflect forms and types that
are recognized at compile time. To avoid an explosion of entries,
@@ -736,7 +2088,7 @@
Buf Str or Array of Int

(Note, however, that these mappings can be overridden by explicit
-definition of the appropriate C<accepts> and C<rejects> methods.
+definition of the appropriate C<ACCEPTS> and C<REJECTS> methods.
If the redefinition occurs at compile time prior to analysis of the
smart match then the information is also available to the optimizer.)

@@ -786,15 +2138,15 @@
There is no pattern matching defined for the C<Any> pattern, so if you
find yourself in the situation of wanting a reversed smartmatch test
with an C<Any> on the right, you can almost always get it by explicit
-call to the underlying C<accepts> method using $_ as the pattern.
+call to the underlying C<ACCEPTS> method using $_ as the pattern.
For example:

$_ X Type of Match Wanted What to use on the right
====== === ==================== ========================
- Code Any scalar sub truth .accepts(X) or .(X)
- Range Any in range .accepts(X)
- Type Any type membership .accepts(X) or .does(X)
- Regex Any pattern match .accepts(X)
+ Code Any scalar sub truth .ACCEPTS(X) or .(X)
+ Range Any in range .ACCEPTS(X)
+ Type Any type membership .ACCEPTS(X) or .does(X)
+ Regex Any pattern match .ACCEPTS(X)
etc.

Similar tricks will allow you to bend the default matching rules for
@@ -807,11 +2159,11 @@

In a pinch you can define a macro to do the "reversed when":

- my macro statement_control:<accepts> () { "when .accepts: " }
+ my macro statement_control:<ACCEPTS> () { "when .ACCEPTS: " }
given $pattern {
- accepts $a { ... }
- accepts $b { ... }
- accepts $c { ... }
+ ACCEPTS $a { ... }
+ ACCEPTS $b { ... }
+ ACCEPTS $c { ... }
}

Various proposed-but-deprecated smartmatch behaviors may be easily
@@ -924,6 +2276,65 @@
However, the structure searched is not guaranteed to maintain a C<.pos>
unless you are searching a C<Str> or C<Cat>.

+=head1 Invocant marker
+
+An appended C<:> marks the invocant when using the indirect-object
+syntax for Perl 6 method calls. The following two statements are
+equivalent:
+
+ $hacker.feed('Pizza and cola');
+ feed $hacker: 'Pizza and cola';
+
+A colon may also be used on an ordinary method call to indicate that
+it should be parsed as a list operator:
+
+ $hacker.feed: 'Pizza and cola';
+
+This colon is a separate token. A colon prefixing an adverb is not
+a separate token. Therefore, under the longest-token rule,
+
+ $hacker.feed:xxx('Pizza and cola');
+
+is tokenized as an adverb applying to the method:
+
+ $hacker.feed :xxx('Pizza and cola');
+
+not as an xxx sub in the argument list of .feed:
+
+ $hacker.feed: xxx('Pizza and cola'); # wrong
+
+If you want both meanings of colon, you have to put it twice:
+
+ $hacker.feed: :xxx('Pizza and cola'), 1,2,3;
+
+(For similar reasons it's required to put whitespace after the colon of a label.)
+
+=head1 Feed operators
+
+The new operators C<< ==> >> and C<< <== >> are akin to UNIX pipes, but
+work with functions that accept and return lists. Since these lists are
+composed of discrete objects and not liquids, we call these I<feed> operators
+rather than pipes. For example,
+
+ @result = map { floor($^x / 2) },
+ grep { /^ \d+ $/ },
+ @data;
+
+can also now be written with rightward feeds as:
+
+ @data ==> grep { /^ \d+ $/ }
+ ==> map { floor($^x / 2) }
+ ==> @result;
+
+or with leftward feeds as:
+
+ @result <== map { floor($^x / 2) }
+ <== grep { /^ \d+ $/ }
+ <== @data;
+
+Either form more clearly indicates the flow of data. See S06 for
+more of the (less-than-obvious) details on these two operators.
+
=head1 Meta operators

Perl 6's operators have been greatly regularized, for instance, by
@@ -1418,7 +2829,7 @@
mean the normal reduction of C<< infix:<\x> >> operator, not the triangular
reduction of C<< infix:<x> >>. This is deemed to be an insignificant problem.

-=head1 Cross operators
+=head2 Cross operators

The final metaoperator is the cross metaoperator. It is formed syntactically
by placing an infix operator between two C<X> characters. It applies the
@@ -1473,7 +2884,7 @@

Multidimensional lists should be handled properly.

-=head1 Nesting of metaoperators
+=head2 Nesting of metaoperators

In order to match operators by the longest-token rule, the
compiler pregenerates various metaforms based on existing operators.
@@ -1513,109 +2924,6 @@
that starts at the length of the current "word" and works down is also
possible.

-=head1 Junctive operators
-
-C<|>, C<&>, and C<^> are no longer bitwise operators (see
-L</Changes to Perl 5 operators>) but now serve a much higher cause:
-they are now the junction constructors.
-
-A junction is a single value that is equivalent to multiple values. They
-thread through operations, returning another junction representing the
-result:
-
- (1|2|3) + 4; # 5|6|7
- (1|2) + (3&4); # (4|5) & (5|6)
-
-Note how when two junctions are applied through an operator, the result
-is a junction representing the operator applied to each combination of
-values.
-
-Junctions come with the functional variants C<any>, C<all>, C<one>, and C<none>.
-
-This opens doors for constructions like:
-
- unless $roll == any(1..6) { print "Invalid roll" }
-
- if $roll == 1|2|3 { print "Low roll" }
-
-Junctions work through subscripting:
-
- doit() if @foo[any(1,2,3)]
-
-Junctions are specifically unordered. So if you say
-
- for all(@foo) {...}
-
-it indicates to the compiler that there is no coupling between loop
-iterations and they can be run in any order or even in parallel. XXX bogus
-
-Use of negative operators with syntactically recognizable junctions may
-produce a warning on code that works differently in English than in Perl.
-Instead of writing
-
- if $a != 1 | 2 | 3 {...}
-
-you need to write
-
- if not $a == 1 | 2 | 3 {...}
-
-However, this is only a syntactic warning, and
-
- if $a != $b {...}
-
-will not complain if $b happens to contain a junction at runtime.
-
-Junctive methods on arrays, lists, and sets work just like the
-corresponding list operators. However, junctive methods on a hash
-make a junction of only the hash's keys. Use the listop form (or an
-explicit C<.pairs>) to make a junction of pairs.
-
-=head1 Chained comparisons
-
-Perl 6 supports the natural extension to the comparison operators,
-allowing multiple operands:
-
- if 1 < $a < 100 { say "Good, you picked a number *between* 1 and 100." }
-
- if 3 < $roll <= 6 { print "High roll" }
-
- if 1 <= $roll1 == $roll2 <= 6 { print "Doubles!" }
-
-A chain of comparisons short-circuits if the first comparison fails:
-
- 1 > 2 > die("this is never reached");
-
-Each argument in the chain will evaluate at most once:
-
- 1 > $x++ > 2 # $x increments exactly once
-
-Note: any operator beginning with C<< < >> must have whitespace
-in front of it, or it will be interpreted as a hash subscript instead.
-
-=head1 Binding
-
-A new form of assignment is present in Perl 6, called I<binding>, used in
-place of typeglob assignment. It is performed with the C<:=> operator.
-Instead of replacing the value in a container like normal assignment, it
-replaces the container itself. For instance:
-
- my $x = 'Just Another';
- my $y := $x;
- $y = 'Perl Hacker';
-
-After this, both C<$x> and C<$y> contain the string C<"Perl Hacker">,
-since they are really just two different names for the same variable.
-
-There is another variant, spelled C<::=>, that does the same thing at
-compile time.
-
-There is also an identity test, C<=:=>, which tests whether two names
-are bound to the same underlying variable. C<$x =:= $y> would return
-true in the above example.
-
-The binding fails if the type of the variable being bound is sufficiently
-inconsistent with the type of the current declaration.
-
=head1 Declarators

The list of variable declarators has expanded from C<my> and C<our>
@@ -1814,65 +3122,6 @@
my \$capture := func();
push |$capture;

-=head1 Feed operators
-
-The new operators C<< ==> >> and C<< <== >> are akin to UNIX pipes, but
-work with functions that accept and return lists. Since these lists are
-composed of discrete objects and not liquids, we call these I<feed> operators
-rather than pipes. For example,
-
- @result = map { floor($^x / 2) },
- grep { /^ \d+ $/ },
- @data;
-
-can also now be written with rightward feeds as:
-
- @data ==> grep { /^ \d+ $/ }
- ==> map { floor($^x / 2) }
- ==> @result;
-
-or with leftward feeds as:
-
- @result <== map { floor($^x / 2) }
- <== grep { /^ \d+ $/ }
- <== @data;
-
-Either form more clearly indicates the flow of data. See S06 for
-more of the (less-than-obvious) details on these two operators.
-
-=head1 Invocant marker
-
-An appended C<:> marks the invocant when using the indirect-object
-syntax for Perl 6 method calls. The following two statements are
-equivalent:
-
- $hacker.feed('Pizza and cola');
- feed $hacker: 'Pizza and cola';
-
-A colon may also be used on an ordinary method call to indicate that
-it should be parsed as a list operator:
-
- $hacker.feed: 'Pizza and cola';
-
-This colon is a separate token. A colon prefixing an adverb is not
-a separate token. Therefore, under the longest-token rule,
-
- $hacker.feed:xxx('Pizza and cola');
-
-is tokenized as an adverb applying to the method:
-
- $hacker.feed :xxx('Pizza and cola');
-
-not as an xxx sub in the argument list of .feed:
-
- $hacker.feed: xxx('Pizza and cola'); # wrong
-
-If you want both meanings of colon, you have to put it twice:
-
- $hacker.feed: :xxx('Pizza and cola'), 1,2,3;
-
-(For similar reasons it's required to put whitespace after the colon of a label.)
-
=head1 Traversing arrays in parallel

In order to support parallel iteration over multiple arrays, Perl 6 has
@@ -1909,27 +3158,6 @@

@foo := [[1,2,3],[4,5,6]]; say cat([;] @foo); # 1,2,3,4,5,6

-=head1 Crossing arrays
-
-In contrast to the zip operator, the C<XX> operator returns all the
-permutations of its sublists. Hence you may say:
-
- <a b> XX <1 2>
-
-and you end up with
-
- ['a', '1'], ['a', '2'], ['b', '1'], ['b', '2']
-
-The C<X> variant crosses the arrays but concatenates strings:
-
- <a b> X <1 2>
-
-produces
-
- 'a1', 'a2', 'b1', 'b2'
-
-The resemblance to C<x> and C<xx> is not entirely accidental.
-
=head1 Minimal whitespace DWIMmery

Whitespace is no longer allowed before the opening bracket of an array
@@ -1971,54 +3199,4 @@
It is possible for C<if()> to also invoke a macro call, but if so, it's a
C<< prefix:<if> >> macro rather than a C<< statement_control:<if> >> macro.

-=head1 Precedence
-
-Perl 6 has 22 precedence levels (which is fewer than Perl 5):
-
- terms 42 3.14 "eek" qq["foo"] [1,2,3] {...} \(@a,$b,%c)
- $x @y %z /abc/ MyType @@multidim $^a
- (1+2) a(1) :by(2) :!verbose :(Dog $self:)
- .meth with implicit invocant $_
- .=meth with implicit invocant $_
- listops leftward
- method postfix .meth .+ .? .* .() .[] .{} .<> .«» .:: .= .^
- autoincrement ++ --
- exponentiation **
- symbolic unary ! + - ~ ? $ @ % & | +^ ~^ ?^ \ ^ =
- multiplicative * / % x xx +& +< +> ~& ~< ~> ?& div mod
- additive + - ~ +| +^ ~| ~^ ?| ?^
- junctive and (all) &
- junctive or (any) | ^
- named unary rand sleep abs etc. -e -r -w -x etc.
- nonchaining binary but does <=> leg cmp
- .. ^.. ..^ ^..^
- ff ^ff ff^ ^ff^
- fff ^fff fff^ ^fff^
- chaining binary != == < <= > >=
- eq ne lt le gt ge
- before after
- ~~ =:= === eqv
- !== !~~ !eq !=:= !=== !eqv etc.
- tight and &&
- tight or || ^^ // min max
- conditional ?? !!
- assignment := ::= =>
- (also = with simple lvalues)
- += -= **= xx= .= etc.
- loose unary true not
- list ops , print push say join split substr open etc.
- any all one none
- die fail warn
- !!! ... ???
- [+] [*] [<] [\+] [\*] etc.
- (also = as list assignment)
- list infix ¥ <== ==> minmax X XX X~X X*X XeqvX etc.
- loose and and
- loose or or xor err
- expr terminator ; {} as control block, statement modifiers
- unmatched ), ], }, etc.
-
-Comma is the only listop that is allowed to occur where an operator is
-expected. All other listops function as a term within the list to the left.
-
=for vim:set expandtab sw=4:

Nicholas Clark

unread,
Jan 27, 2007, 1:18:50 PM1/27/07
to la...@cvs.perl.org, perl6-l...@perl.org
On Sat, Jan 27, 2007 at 12:59:59AM -0800, la...@cvs.perl.org wrote:

> +As in C, these operators increment or decrement the object in question
> +either before or after the value is taken from the object, depending on
> +whether it is put before or after. Also as in C, use of multiple side
> +effects on a single object in the same expression results in undefined
> +behavior unless some explicit sequencing operator is interposed.

Nothing in the repository yet defines what is a sequencing operator.

Also, I'm never totally confident on what isn't quite undefined behaviour in
C, but something like

$a = $b + ++$b;

doesn't appear to have multiple side effects, yet it ought to be undefined.
(Unless "reading a value you also modified" counts as a side effect)

> +infix:<**> exponentiation operator
> +
> + $x ** 2
> +
> +If the right argument is not an integer, the result is likely to
> +be an approximation. If the right argument is of an integer type,
> +exponentiation is at least as accurate as repeated multiplication on
> +the left side's type. (From which it can be deduced that C<Int**Int>
> +is always exact, since Int supports arbitrary precision.) If the

I believe that that should start with "positive integer type"

3 ** -1

is unlikely to be accurate.

> +For instance, C<=$iterator> is scalar/list sensitive and will

should that be item/list?

> +infix:<//>, defined-or
> +
> + //
> +
> +Returns the left argument if it's defined, otherwise the right argument.
> +In list context forces a false return to mean C<()>.
> +See C<err> below for low-precedence version.

Is this short-circuiting?

> +=head2 Conditional precedence
> +
> +=over
> +
> +=item *
> +
> +?? !!
> +
> + say "My answer is: ", $maybe ?? "yes" !! "no";
> +
> +It is a syntax error to use an
> +operator in the middle that binds looser in precedence, such as C<=>.

This doesn't make it explicit that only one of "yes" or "no" is evaluated.
Then again, neither does the Perl 5 documentation.

> +Binary C<< => >> is no longer just a "fancy comma". It now constructs
> +a C<Pair> object that can, among other things, be used to pass named
> +arguments to functions. It provides scalar context to both sides.

Should that be "item" ?


> +The minmax operator
> +
> + $min0, $max0 minmax $min1, $max1 # ($min0 min $min1, $max0 max $max1)

This explanation doesn't make sense to me. Should I drink more coffee?

> +infix:<and>
> +
> + and
> +
> +Returns the left argument if the left argument is false, otherwise returns
> +the right argument. In list context forces a false return to mean C<()>.
> +See C<&&> above for high-precedence version.

As these are short circuiting, would it be better to say
"otherwise evaluates and returns the right argument"

(likewise for or and err)

Is it defined that $a + $b evaluates the arguments in any particular order?
Even guaranteeing that either the left or the right gets completely evaluated
first would be better than C :-)

Nicholas Clark

John Macdonald

unread,
Jan 27, 2007, 6:56:43 PM1/27/07
to la...@cvs.perl.org, perl6-l...@perl.org
On Sat, Jan 27, 2007 at 06:18:50PM +0000, Nicholas Clark wrote:
> Is it defined that $a + $b evaluates the arguments in any particular order?
> Even guaranteeing that either the left or the right gets completely evaluated
> first would be better than C :-)

In C, that is deliberately left undefined to allow the code
generator to have more flexibility in optimizing the code
it generates. It's always easy to separate side-effects into
multiple statements that are executed in the desired order
if you need a specific order. If everything in the language
implies a specific order, no opportunity for optimization
remains - even if there is no actual necessity for the
particular order to be followed.

--

Aaron Crane

unread,
Jan 28, 2007, 1:57:53 PM1/28/07
to perl6-l...@perl.org
Nicholas Clark writes:
> Also, I'm never totally confident on what isn't quite undefined behaviour in
> C, but something like
>
> $a = $b + ++$b;
>
> doesn't appear to have multiple side effects, yet it ought to be undefined.

It is undefined in C. The standard says that between any adjacent pair
of sequence points,

an object shall have its stored value modified at most once by the
evaluation of an expression. Furthermore, the prior value shall be
accessed only to determine the value to be stored.

C<b + ++b> modifies b once, reads it once to determine the value to be
stored (C<++b), and also reads it one further time (to determine the
result of the addition), so it's undefined.

--
Aaron Crane

0 new messages