Author: lwall
Date: 2009-07-11 01:11:48 +0200 (Sat, 11 Jul 2009)
New Revision: 27503

Modified:
   docs/Perl6/Spec/S03-operators.pod
Log:
[S03] Reduce power of Pair.ACCEPTS to work only on booleans, moritz++
(but we keep the pair forms for ease-of-use via switches and junctions
as well as for "doesn't look like anything else" readability).
Specify that numeric comparisons must use the method forms (except for == 0).
Filetest methods and pair matching no longer work on Str.
(They do, however work on IO, Statbuf, and will presumably work extensibly
on any other resource handles we care to define in the future.)


Modified: docs/Perl6/Spec/S03-operators.pod
===================================================================
--- docs/Perl6/Spec/S03-operators.pod   2009-07-10 19:36:51 UTC (rev 27502)
+++ docs/Perl6/Spec/S03-operators.pod   2009-07-10 23:11:48 UTC (rev 27503)
@@ -14,8 +14,8 @@
 
     Created: 8 Mar 2004
 
-    Last Modified: 10 Jun 2009
-    Version: 168
+    Last Modified: 10 Jul 2009
+    Version: 169
 
 =head1 Overview
 
@@ -2215,15 +2215,15 @@
 The filetest operators are gone.  We now use a C<Pair> as a
 pattern that calls an object's method:
 
-    if $filename ~~ :e { say "exists" }
+    if $filename.IO ~~ :e { say "exists" }
 
 is the same as
 
-    if $filename.e { say "exists" }
+    if $filename.IO.e { say "exists" }
 
 The 1st form actually translates to the latter form, so the object's
 class decides how to dispatch methods.  It just happens that
-C<Str> (filenames), C<IO> (filehandles), and C<Statbuf> (stat buffers)
+C<IO> (filehandles) and C<Statbuf> (stat buffers)
 default to the expected filetest semantics, but C<$regex.i> might
 tell you whether the regex is case insensitive, for instance.
 
@@ -2245,19 +2245,31 @@
     when :r & :w & :x
     when all(:r,:w,:x)
 
-The advantage of the method form is that it can be used in places that
-require tighter precedence than C<~~> provides:
+The pair forms are useful only for boolean tests, so the
+method form must be used for any numeric-based tests:
 
-    sort { $^a.M <=> $^b.M }, @files
+    if stat($filename).s > 1024 {...}
 
+However, these still work:
+
+    given $fh {
+        when :s  {...} # file has size > 0
+        when :!s {...} # file size == 0
+    }
+
+One advantage of the method form is that it can be used in places that
+require tighter precedence than C<~~> provides
+
+    sort { $^a.M <=> $^b.M }, @files».IO
+
 though that's a silly example since you could just write:
 
-    sort { .M }, @files
+    sort { .M }, @files».IO
 
 But that demonstrates the other advantage of the method form, which is
 that it allows the "unary dot" syntax to test the current topic.
 
-Unlike in earlier versions of Perl 6, these filetests do not return
+Unlike in earlier versions of Perl 6, these filetest methods do not return
 stat buffers, but simple scalars of type C<Bool>, C<Int>, or C<Num>.
 
 In general, the user need not worry about caching the stat buffer
@@ -2272,11 +2284,6 @@
 object doesn't know its filename but does know its IO handle, then
 C<.file> attempts to return C<.io.file>.
 
-Note that C<:s> still returns the filesize, but C<:!s> is true
-only if the file is of size 0, since it is smartmatched
-against the implicit False argument.  By the same token,
-C<:s(0..1024)> will be true only for files of size 1K or less.
-
 (Inadvertent use of the Perl 5 forms will normally result in treatment
 as a negated postdeclared subroutine, which is likely to produce an
 error message at the end of compilation.)
@@ -3077,7 +3084,7 @@
     Any       Str       string equality         ~$_ eq X
 
     Hash      Pair      test hash mapping       $_{X.key} ~~ X.value
-    Any       Pair      test object attribute   ."{X.key}" ~~ X.value (e.g. 
filetests)
+    Any       Pair      test object attribute   ?."{X.key}" === ?X.value (e.g. 
filetests)
 
     Set       Set       identical sets          $_ === X
     Hash      Set       hash keys same set      $_.keys === X
@@ -3538,7 +3545,7 @@
 Note that logical operators such as C<||> and C<^^> do not return a Bool,
 but rather one of the operands.
 
-=head2 Reversed comparison operators
+=head2 Reversed operators
 
 Any infix operator may be called with its two arguments reversed
 by prefixing with C<R>.  For instance, to do reversed comparisons:

Reply via email to