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. -- Bacek
diff --git a/languages/perl6/src/classes/Bool.pir b/languages/perl6/src/classes/Bool.pir index bcdcffb..6fd8ce8 100644 --- a/languages/perl6/src/classes/Bool.pir +++ b/languages/perl6/src/classes/Bool.pir @@ -63,6 +63,24 @@ This is a value type, so just returns itself. 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' + .return($P0) + ret_true: + $P0 = get_hll_global ['Bool'], 'True' + .return($P0) +.end + # Local Variables: # mode: pir