Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Bool.pick in Rakudo #384

Closed
p6rt opened this issue Nov 1, 2008 · 11 comments
Closed

Implement Bool.pick in Rakudo #384

p6rt opened this issue Nov 1, 2008 · 11 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Nov 1, 2008

Migrated from rt.perl.org#60290 (status was 'resolved')

Searchable as RT60290$

@p6rt
Copy link
Author

p6rt commented Nov 1, 2008

From @masak

...or, if easier, .pick on all enum types.

Rakudo r32267 recognizes 'Bool.pick' as a valid program, but hangs
when running it. It also hangs for all other defined classes except
'Bool'.

@p6rt
Copy link
Author

p6rt commented Nov 2, 2008

From @masak

Carl (>)​:

Rakudo r32267 recognizes 'Bool.pick' as a valid program, but hangs
when running it. It also hangs for all other defined classes except
'Bool'.

Found and fixed the hanging problem in r32280, with the help of jonathan++.

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.

@p6rt
Copy link
Author

p6rt commented Nov 2, 2008

@masak - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Nov 9, 2008

From @bacek

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

@p6rt
Copy link
Author

p6rt commented Nov 9, 2008

From @bacek

bool_pick.patch
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

@p6rt
Copy link
Author

p6rt commented Nov 9, 2008

From @pmichaud

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.)

Pm

@p6rt
Copy link
Author

p6rt commented Nov 10, 2008

From @pmichaud

Applied (with minor improvements) in r32477, thanks!

Pm

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 10, 2008

From @pmichaud

Applied (with minor improvements) in r32477, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Nov 10, 2008

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Nov 10, 2008
@p6rt
Copy link
Author

p6rt commented Nov 10, 2008

From @bacek

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

@p6rt
Copy link
Author

p6rt commented Nov 10, 2008

From @bacek

bool_pick2.patch
commit da5c54927e251a7f99045c9b5c1f60faa4e29dd4
Author: Vasily Chekalkin <bacek@haste.optusnet.com.au>
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

@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant