On Wed Apr 01 22:00:57 2009, wayland wrote:
> <wayland76> rakudo: my Bool $t; $t = Bool::True; print $t.succ
>       I don't know what it should do, but not Null PMC.

I would think it would do somthing like:

<moritz_> rakudo: my $x = Bool::True; say ++$x
<p6eval> rakudo 881ed3: OUTPUT«1␤» 

and the attached patches provide and test for such behavior.  Note that 
the patch should, and does, also gracefully handle "say $t.succ.perl".  

The patch is not quite as simple as it might be because I will still 
suggest that, at some point, Int and Str should effectively inherit 
the 'pred' and 'succ' functions provided in this patch for Bool.

Index: t/spec/S02-builtin_data_types/bool.t
===================================================================
--- t/spec/S02-builtin_data_types/bool.t        (revision 26063)
+++ t/spec/S02-builtin_data_types/bool.t        (working copy)
@@ -5,7 +5,7 @@
 
 # L<S12/Enums/"Two built-in enums are">
 
-plan 24;
+plan 28;
 
 # tests True and False are Bool's
 isa_ok(Bool::True, Bool);
@@ -55,4 +55,9 @@
 is(++$bool, Bool::True, 'Increment of Bool::True still produces Bool::True');
 is(--$bool, Bool::False, 'Decrement of Bool::True produces Bool::False');
 is(--$bool, Bool::False, 'Decrement of Bool::False produces Bool::False');
-
+# remember $bool still false from above
+is($bool.succ, Bool::True, 'Successor of Bool::False returns Bool::True');
+is($bool.succ.succ, Bool::True, 'Successor twice of Bool::True still returns 
Bool::True');
+$bool .= succ;
+is($bool.pred, Bool::False, 'Predecessor of Bool::True returns Bool::False');
+is($bool.pred.pred, Bool::False, 'Predecessor twice of Bool::True still 
returns Bool::False');
diff --git a/src/classes/Bool.pir b/src/classes/Bool.pir
index 303d3e2..4b1d0b3 100644
--- a/src/classes/Bool.pir
+++ b/src/classes/Bool.pir
@@ -39,12 +39,12 @@ symbols for C<Bool::True> and C<Bool::False>.
 .end
 
 
-.sub 'succ' :method :vtable('increment')
+.sub '' :method :vtable('increment')
     self = 1
 .end
 
 
-.sub 'pred' :method :vtable('decrement')
+.sub '' :method :vtable('decrement')
     self = 0
 .end
 
--- a/src/setting/Bool.pm
+++ b/src/setting/Bool.pm
@@ -23,6 +23,26 @@ Returns True or False
         return rand < 0.5 ?? Bool::True !! Bool::False;
     }
 
+=begin item succ
+
+Returns True 
+
+=end item
+
+    method succ() {
+        return ++(self.clone)
+    }
+
+=begin item pred
+
+Returns False
+
+=end item
+
+    method pred() {
+        return --(self.clone)
+    }
+
 }
 
 # vim: ft=perl6

Reply via email to