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

2006-02-25 Thread larry
Author: larry
Date: Fri Feb 24 16:04:13 2006
New Revision: 7860

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

Log:
* Added $() access to result object.
* Added ( pat ) matcher to capture simple result object.
* Changed old (...) assertion to ?{...} and !{...},
which is more consistent with other callouts to code.


Modified: doc/trunk/design/syn/S05.pod
==
--- doc/trunk/design/syn/S05.pod(original)
+++ doc/trunk/design/syn/S05.podFri Feb 24 16:04:13 2006
@@ -13,9 +13,9 @@
 
Maintainer: Patrick Michaud [EMAIL PROTECTED]
Date: 24 Jun 2002
-   Last Modified: 24 Feb 2006
+   Last Modified: 25 Feb 2006
Number: 5
-   Version: 10
+   Version: 11
 
 This document summarizes Apocalypse 5, which is about the new regex
 syntax.  We now try to call them rules because they haven't been
@@ -613,24 +613,40 @@
 
 =item *
 
-A leading C( indicates a code assertion:
+A leading C?{ or C!{indicates a code assertion:
 
- / (\d**{1..3}) ( $0  256 ) /
+ / (\d**{1..3}) ?{ $0  256 } /
+ / (\d**{1..3}) !{ $0  256 } /
 
 Similar to:
 
  / (\d**{1..3}) { $0  256 or fail } /
+ / (\d**{1..3}) { $0  256 and fail } /
 
 Unlike closures, code assertions are not guaranteed to be run at the
 canonical time if the optimizer can prove something later can't match.
 So you can sneak in a call to a non-canonical closure that way:
 
- /^foo .* ( do { say Got here! } or 1 ) .* bar$/
+ /^foo .* ?{ do { say Got here! } or 1 } .* bar$/
 
 The Cdo block is unlikely to run unless the string ends with Cbar.
 
 =item *
 
+A leading C( indicates the start of a result capture:
+
+/ foo ( \d+ ) bar /
+
+is equivalent to:
+
+/ before foo \d+ after bar /
+
+except that the scan for foo can be done in the forward direction,
+when a lookbehind assertion would scan for \d+ and then match foo
+backwards.
+
+=item *
+
 A leading C[ or C+ indicates an enumerated character class.  Ranges
 in enumerated character classes are indicated with C...
 
@@ -1041,14 +1057,19 @@
 
 =item *
 
-A match always returns a match object, which is also available as
-(lexical) C$/ (except within a closure lexically embedded in a rule,
-where C$/ always refers to the current match, not any submatch done
-within the closure).
+A match always returns a match object, which is also available
+as C$/, which is an environmental lexical declared in the outer
+subroutine that is calling the rule.  (A closure lexically embedded
+in a rule does not redeclare C$/, so C$/ always refers to the
+current match, not any prior submatch done within the closure).
 
 =item *
 
-The match object evaluates differently in different contexts:
+Notionally, a match object contains (among other things) a boolean
+success value, a scalar result object, an array of ordered submatch
+objects, and a hash of named submatch objects.  To provide convenient
+access to these various values, the match object evaluates differently
+in different contexts:
 
 =over
 
@@ -1083,7 +1104,7 @@
 
 =item *
 
-When used as a closure, a Match object evaluates to its underlying
+When called as a closure, a Match object evaluates to its underlying
 result object.  Usually this is just the entire match string, but
 you can override that by calling Creturn inside a rule:
 
@@ -1093,6 +1114,18 @@
 # match succeeds -- ignore the rest of the rule
 }.();
 
+C$() is a shorthand for C$/.() or C$/().  The result object
+may contain any object, not just a string.
+
+You may also capture a subset of the match as the result object using
+the C (...) construct:
+
+foo123bar ~~ / foo ( \d+ \ bar /
+say $();# says 123
+
+In this case the result object is always a string when doing string
+matching, and a list of one or more elements when doing array matching.
+
 =item *
 
 When used as an array, a Match object pretends to be an array of all
@@ -1175,9 +1208,19 @@
 incomplete CMatch object (which can be modified via the internal C$/.
 For example:
 
- $str ~~ / foo# Match 'foo'
+$str ~~ / foo# Match 'foo'
{ $/ = 'bar' } # But pretend we matched 'bar'
  /;
+say $/;   # says 'bar'
+
+This is slightly dangerous, insofar as you might return something that
+does not behave like a CMatch object to some context that requires
+one.  Fortunately, you normally just want to return a result object instead:
+
+$str ~~ / foo # Match 'foo'
+   { return 'bar' }   # But pretend we matched 'bar'
+ /;
+say $();  # says 'bar'
 
 =back
 


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

2006-02-25 Thread larry
Author: larry
Date: Sat Feb 25 00:29:54 2006
New Revision: 7863

Modified:
   doc/trunk/design/syn/S02.pod
   doc/trunk/design/syn/S03.pod
   doc/trunk/design/syn/S04.pod
   doc/trunk/design/syn/S05.pod

Log:
Various tweaks and comments from TheDamian.


Modified: doc/trunk/design/syn/S02.pod
==
--- doc/trunk/design/syn/S02.pod(original)
+++ doc/trunk/design/syn/S02.podSat Feb 25 00:29:54 2006
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall [EMAIL PROTECTED]
   Date: 10 Aug 2004
-  Last Modified: 16 Feb 2006
+  Last Modified: 25 Feb 2006
   Number: 2
-  Version: 16
+  Version: 17
 
 This document summarizes Apocalypse 2, which covers small-scale
 lexical items and typological issues.  (These Synopses also contain
@@ -111,7 +111,7 @@
 =item *
 
 In support of OO encapsulation, there is a new fundamental datatype:
-Bopaque.  External access to opaque objects is always through method
+BP6opaque.  External access to opaque objects is always through method
 calls, even for attributes.
 
 =item *
@@ -211,9 +211,11 @@
 
 =item *
 
-Perl 6 intrinsically supports big integers and rationals through
-its system of type declarations.  CInt automatically supports
-promotion to arbitrary precision.  CRat supports arbitrary precision
+Perl 6 intrinsically supports big integers and rationals through its
+system of type declarations.  CInt automatically supports promotion
+to arbitrary precision.  (CNum may support arbitrary-precision
+floating-point arithmatic, but is not required to unless we can do
+so portably and efficiently.)  CRat supports arbitrary precision
 rational arithmetic.  Value types like Cint and Cnum imply
 the natural machine representation for integers and floating-point
 numbers, respectively, and do not promote to arbitrary precision.

Modified: doc/trunk/design/syn/S03.pod
==
--- doc/trunk/design/syn/S03.pod(original)
+++ doc/trunk/design/syn/S03.podSat Feb 25 00:29:54 2006
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall [EMAIL PROTECTED]
   Date: 8 Mar 2004
-  Last Modified: 1 Feb 2006
+  Last Modified: 25 Feb 2006
   Number: 3
-  Version: 12
+  Version: 13
 
 =head1 Operator renaming
 
@@ -107,10 +107,10 @@
 of semantics.  Anywhere you used C=~ before you now use C~~, but C~~ is
 much more general now.  See LSynopsis 4 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~~ instead,
+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.)
 
-=item * Unary C. calls its single argument (which must be a method, or an
+=item * Unary C. calls its single argument (which must be a method, or a
 dereferencer for a hash or array) on C$_.
 
 =item * The C.. range operator has variants with C^ on either
@@ -118,10 +118,18 @@
 produces a Range object.  Range objects are lazy iterators, and can
 be interrogated for their current C.min and C.max values (which
 change as they are iterated).  Ranges are not autoreversing: C2..1
-is always a null range, as is C1^..^2.  However, smart matching
-against a Range object smartmatches the endpoints in the domain of
-the object being matched, so C 1.5 ~~ 1^..^2  is true.
-(But C 2.1 ~~ 1..2  is false.)
+is always a null range, as is C1^..^2.  To reverse a range use:
+
+2..1:by(-1)
+reverse 1..2
+
+(The Creverse is preferred because it works for alphabetic ranges
+as well.)
+
+Because CRange objects are lazy, they do not automatically generate
+a list.  So smart matching against a Range object smartmatches the
+endpoints in the domain of the object being matched, so C 1.5 ~~
+1^..^2  is true.  (But C 2.1 ~~ 1..2  is false.)
 
 =item * The unary C^ operator generates a range from C0 up to
 one less than its argument.  so C^4 is short for C0..^4 or C0..3.
@@ -133,7 +141,7 @@
 
 =item * However, C... as a term is the yada, yada, yada operator,
 which is used as the body in function prototypes.  It complains
-bitterly if it is ever executed.  Actually, it calls Cfail.  Variant
+bitterly (by calling Cfail) if it is ever executed.  Variant
 C??? calls Cwarn, and C!!! calls Cdie.
 
 =item * In addition, to the ordinary C. method invocation, there are
@@ -432,7 +440,7 @@
 
 =head1 Precedence
 
-Perl 6 has 22 precedence levels (fewer than Perl 5):
+Perl 6 has 22 precedence levels (which is fewer than Perl 5):
 
 terms  42 eek $x /abc/ (1+2) a(1) :by(2) .meth listop
 method postfix . .+ .? .* .() .[] .{} .«» .=

Modified: doc/trunk/design/syn/S04.pod
==
--- doc/trunk/design/syn/S04.pod(original)
+++ doc/trunk/design/syn/S04.podSat Feb 25 00:29:54 2006
@@ -12,9 +12,9 

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

2006-02-25 Thread autrijus
Author: autrijus
Date: Sat Feb 25 01:59:19 2006
New Revision: 7867

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

Log:
* S05: Fix the (...) typo (was spelled (...\) and
  make the moose example slightly more idiomatic.

Modified: doc/trunk/design/syn/S05.pod
==
--- doc/trunk/design/syn/S05.pod(original)
+++ doc/trunk/design/syn/S05.podSat Feb 25 01:59:19 2006
@@ -1115,17 +1115,17 @@
 
 my $moose = m:{
 antler body
-{ return Moose.new( body = $body.attach(:$antler) ) }
+{ return Moose.new( body = $body().attach($antler()) ) }
 # match succeeds -- ignore the rest of the rule
 }.();
 
 C$() is a shorthand for C$/.() or C$/().  The result object
-may contain any object, not just a string.
+may be of any type, not just a string.
 
 You may also capture a subset of the match as the result object using
 the C (...) construct:
 
-foo123bar ~~ / foo ( \d+ \ bar /
+foo123bar ~~ / foo ( \d+ ) bar /
 say $();# says 123
 
 In this case the result object is always a string when doing string


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

2006-02-25 Thread larry
Author: larry
Date: Sat Feb 25 01:58:24 2006
New Revision: 7866

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

Log:
Fixed and clarified (...) definition.


Modified: doc/trunk/design/syn/S05.pod
==
--- doc/trunk/design/syn/S05.pod(original)
+++ doc/trunk/design/syn/S05.podSat Feb 25 01:58:24 2006
@@ -639,11 +639,16 @@
 
 is equivalent to:
 
-/ before foo \d+ after bar /
+/ after foo \d+ before bar /
 
 except that the scan for foo can be done in the forward direction,
-when a lookbehind assertion would scan for \d+ and then match foo
-backwards.
+while a lookbehind assertion would presumably scan for \d+ and then
+match foo backwards.  The use of C (...)  affects only the
+meaning of the result object and the positions of the beginning and
+ending of the match.  That is, after the match above, C$() contains
+only the digits matched, and C.pos is pointing to after the digits.
+Other captures (named or numbered) are unaffected and may be accessed
+through C$/.
 
 =item *
 


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

2006-02-25 Thread larry
Author: larry
Date: Sat Feb 25 02:30:24 2006
New Revision: 7869

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

Log:
Example was still in superpositional Perl[5|6]. dconway++ lwall--


Modified: doc/trunk/design/syn/S04.pod
==
--- doc/trunk/design/syn/S04.pod(original)
+++ doc/trunk/design/syn/S04.podSat Feb 25 02:30:24 2006
@@ -210,9 +210,10 @@
 The list is evaluated lazily by default, so instead of using a Cwhile
 to read a file a line at a time as you would in Perl 5:
 
-while my $line = $*IN {...}
+while (my $line = STDIN) {...}
 
-in Perl 6 you should use a Cfor instead:
+in Perl 6 you should use a Cfor (plus a unary C= iterate the
+iterator operator) instead:
 
 for =$*IN - $line {...}