Author: larry
Date: Sat Jul 15 00:15:51 2006
New Revision: 10217
Modified:
doc/trunk/design/syn/S03.pod
Log:
More clarifications, many suggested by dduncan++.
Modified: doc/trunk/design/syn/S03.pod
==
--- doc/trunk/design/syn/S03.pod(original)
+++ doc/trunk/design/syn/S03.podSat Jul 15 00:15:51 2006
@@ -12,9 +12,9 @@
Maintainer: Larry Wall <[EMAIL PROTECTED]>
Date: 8 Mar 2004
- Last Modified: 14 Jul 2006
+ Last Modified: 15 Jul 2006
Number: 3
- Version: 47
+ Version: 48
=head1 Changes to existing operators
@@ -29,7 +29,8 @@
=item * C<< -> >> becomes C<.>, like the rest of the world uses.
=item * The string concatenation C<.> becomes C<~>. Think of it as
-"stitching" the two ends of its arguments together.
+"stitching" the two ends of its arguments together. String append
+is likewise C<~=>.
=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
@@ -50,17 +51,31 @@
so you need C<$($foo[bar])> to mean the other way.
=item * Bitwise operators get a data type prefix: C<+>, C<~>, or C.
-For example, C<|> becomes either C<+|> or C<~|> or C, depending on
-whether the operands are to be treated as numbers, strings, or boolean
-values. Left shift C< << > becomes C< +< >, and correspondingly with
-right shift. Unary C<~> becomes either C<+^> or C<~^> or C, since a
-bitwise NOT is like an exclusive-or against solid ones. Note that C
-is functionally identical to C. C differs from C<||> in that
-C always returns a standard boolean value (either 1 or 0), whereas
-C<||> return the actual value of the first of its arguments that is
-true. Bitwise string operators may only be applied to C types or
-similar compact integer arrays, and treat the entire chunk of memory
-as a single huge integer.
+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
+C< +< >, and correspondingly with right shift. Perl 5's unary C<~>
+(one's complement) becomes either C<+^> or C<~^> or C, since a
+bitwise NOT is like an exclusive-or against solid ones. Note that
+C is functionally identical to C, but conceptually coerces to
+boolean first and then flips the bit. Please use C instead.
+
+C is a logical OR but differs from C<||> in that C always
+evaluates both sides and returns a standard boolean value. That is,
+it's equivalent to C<< ?$a + ?$b != 0 >>. Another difference is that
+it has the precedence of an additive operator.
+
+C is a logical AND but differs from C<&&> in that C always
+evaluates both sides and returns a standard boolean value. That is,
+it's equivalent to C<< ?$a * ?$b != 0 >>. Another difference is that
+it has the precedence of a multiplicative operator.
+
+Bitwise string operators (those starting with C<~>) may only be
+applied to C types or similar compact integer arrays, and treat
+the entire chunk of memory as a single huge integer. They differ from
+the C<+> operators in that the C<+> operators would try to convert
+the string to a number first on the assumption that the string was an
+ASCII representation of a number.
=item * C splits into two operators: C (which concatenates repetitions
of a string to produce a single string), and C (which creates a list of
@@ -108,7 +123,7 @@
($a,$b,$c) = 1,2,3;
-since list assignment operators are of assignment precedence to their left.
+since assignment operators are tighter than comma to their left.
=item * The scalar assignment operator still parses as it did before, so
@@ -379,7 +394,8 @@
in terms of C, so C<$a leg $b> is now defined as C<~$a cmp ~$b>.
The sort operator still defaults to C rather than C. The
C<< <=> >> operator's semantics are unchanged except that it returns
-an C value as described above.
+an C value as described above. In other words, C<< $a <=> $b >>
+is now equivalent to C<+$a cmp +$b>.
=item * Binary C<< => >> is no longer just a "fancy comma". It now
constructs a C object that can, among other things, be used to
@@ -393,8 +409,9 @@
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<~=> instead, or to put a space between if they really wanted to assign
-a stringified value.)
+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 a postfix operator)
on C<$_>. (It's not really a unary operator, so we put it in quotes.)
@@ -582,11 +599,22 @@
=head1 Meta operators
Perl 6's operators have been greatly regularized, f