Patrick R. Michaud wrote:
On Sat, Nov 08, 2008 at 07:35:57PM -0800, Vasily Chekalkin via RT wrote:
On Sun Nov 02 03:43:27 2008, masak wrote:
The core issue of this ticket still remains, though: to implement
Bool.pick in such a way that it returns either Bool::True or Bool::False.
Ad-hoc implementation attached. I still trying to implement Enum.pick.

Note that according to the current S29, .pick returns a List.
(There has been some discussion on #perl6 that .pick should return
a Capture instead.)

Ah, ok. Revised patch attached.

--
Bacek
commit da5c54927e251a7f99045c9b5c1f60faa4e29dd4
Author: Vasily Chekalkin <[EMAIL PROTECTED]>
Date:   Mon Nov 10 13:03:11 2008 +1100

    Bool.pick

diff --git a/languages/perl6/src/classes/Bool.pir b/languages/perl6/src/classes/Bool.pir
index 129466a..44c2b37 100644
--- a/languages/perl6/src/classes/Bool.pir
+++ b/languages/perl6/src/classes/Bool.pir
@@ -52,6 +52,29 @@ symbols for C<Bool::True> and C<Bool::False>.
     self = 0
 .end
 
+=item
+
+Bool.pick - returns True or False
+
+=cut
+
+.sub 'pick' :method
+    .local pmc rand
+    rand = get_hll_global ['Any'], '$!random'
+    $N0 = rand
+    if $N0 < 0.5 goto ret_true
+    $P0 = get_hll_global ['Bool'], 'False'
+    goto done
+  ret_true:
+    $P0 = get_hll_global ['Bool'], 'True'
+
+  done:
+    .local pmc result
+    result = 'list'()
+    push result, $P0
+    .return(result)
+.end
+
 
 # Local Variables:
 #   mode: pir

Reply via email to