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

Bool.pick always returns false. #1894

Closed
p6rt opened this issue Jun 28, 2010 · 10 comments
Closed

Bool.pick always returns false. #1894

p6rt opened this issue Jun 28, 2010 · 10 comments

Comments

@p6rt
Copy link

p6rt commented Jun 28, 2010

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

Searchable as RT76238$

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From lembark@wrkhors.com

Using the June release​:

$ perl6 --version
This compiler is built with the Parrot Compiler Toolkit, parrot revision 47640.

Attempting to print some random numers via Bool.pick
gives no output​:

  #!/opt/parrot/bin/perl6

  use v6;

  .say if Bool.pick for ^100;

  $ perl6 hak
  $

The same basic process using (0..1) does work​:

  $ cat hak
  #!/opt/parrot/bin/perl6

  use v6;

  .say if (^2).pick for ^100;

  $ perl6 hak
  0
  2
  3
  4
  <snip>

I get the same result from the command line with a file
or the perl6 interactive prompt.

--
Steven Lembark 85-09 90th St.
Workhorse Computing Woodhaven, NY, 11421
lembark@​wrkhors.com +1 888 359 3508

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @pmichaud

On Mon Jun 28 04​:49​:23 2010, lembark@​wrkhors.com wrote​:

Using the June release​:

$ perl6 --version
This compiler is built with the Parrot Compiler Toolkit, parrot
revision 47640.

Attempting to print some random numers via Bool.pick
gives no output​:

For a wide variety of reasons, Rakudo currently implements Bool as a
fundamental type rather than an enumeration. As such, Bool.pick is
acting the same as if one had written "Int.pick" or "Num.pick" -- it's
treating the invocant as a list of one element and then returning the
type object directly. And Bool as a type object always returns false
because it is undefined.

For now, the workaround is to do (False,True).pick until we can properly
implement .pick on enumerations, and figure out how to turn Bool into
one (or convince the specification that Bool is not really an
enumeration :-).

Pm

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 28, 2010

From @markjreed

That is terribly confusing. I'm tempted to argue for .pick not being
defined on scalar values.

Do any of the other non-Enumerated types besides Bool have a finite
range? I'd say .pick should return an appropriate random value when
applied to any such.

On Monday, June 28, 2010, Patrick R. Michaud via RT
<perl6-bugs-followup@​perl.org> wrote​:

On Mon Jun 28 04​:49​:23 2010, lembark@​wrkhors.com wrote​:

Using the June release​:

$ perl6 --version
This compiler is built with the Parrot Compiler Toolkit, parrot
revision 47640.

Attempting to print some random numers via Bool.pick
gives no output​:

For a wide variety of reasons, Rakudo currently implements Bool as a
fundamental type rather than an enumeration.  As such, Bool.pick is
acting the same as if one had written "Int.pick" or "Num.pick" -- it's
treating the invocant as a list of one element and then returning the
type object directly.  And Bool as a type object always returns false
because it is undefined.

For now, the workaround is to do (False,True).pick until we can properly
implement .pick on enumerations, and figure out how to turn Bool into
one (or convince the specification that Bool is not really an
enumeration :-).

Pm

--
Mark J. Reed <markjreed@​gmail.com>

@p6rt
Copy link
Author

p6rt commented Jun 29, 2010

From @masak

On Mon Jun 28 11​:38​:07 2010, markjreed wrote​:

That is terribly confusing. I'm tempted to argue for .pick not being
defined on scalar values.

Do any of the other non-Enumerated types besides Bool have a finite
range? I'd say .pick should return an appropriate random value when
applied to any such.

I think you misunderstand.

The confusion doesn't originate in Perl 6, but in Rakudo. It wouldn't manifest if Bool were
implemented as an enumeration type.

Bool is an enumerated type in the spec. By the spec, .pick on an enumeration type *should*
already return an appropriate random value. So far in Rakudo, Bool hasn't been implemented
as an enumeration type. Therefore (and only therefore) are you seeing this result. Arguing for
.pick not being defined on scalar values doesn't make any sense.

If it's really really important that Bool.pick return a random Bool, you can always inject your
own .pick method in Bool to do this​:

  use MONKEY_TYPING;
  augment class Bool {
  method pick() {
  defined self ?? self !! (True, False).pick
  }
  }

In fact, I see no reason not to patch Rakudo itself with this method for the time being.

@p6rt
Copy link
Author

p6rt commented Jun 30, 2010

From @markjreed

I didn't misunderstand. I just find it confusing that $foo.pick
returns $foo when $foo isn't a collection. It's logical but
surprising, orthogonal instead of diagonal. I'd rather see .pick fail
for non-collections.

I get that Bool.pick is supposed to work either way.

On Tuesday, June 29, 2010, Carl Mäsak via RT
<perl6-bugs-followup@​perl.org> wrote​:

On Mon Jun 28 11​:38​:07 2010, markjreed wrote​:

That is terribly confusing.  I'm tempted to argue for .pick not being
defined on scalar values.

Do any of the other non-Enumerated types besides Bool have a finite
range?  I'd say .pick should return an appropriate random value when
applied to any such.

I think you misunderstand.

The confusion doesn't originate in Perl 6, but in Rakudo. It wouldn't manifest if Bool were
implemented as an enumeration type.

Bool is an enumerated type in the spec. By the spec, .pick on an enumeration type *should*
already return an appropriate random value. So far in Rakudo, Bool hasn't been implemented
as an enumeration type. Therefore (and only therefore) are you seeing this result. Arguing for
.pick not being defined on scalar values doesn't make any sense.

If it's really really important that Bool.pick return a random Bool, you can always inject your
own .pick method in Bool to do this​:

 use MONKEY_TYPING;
 augment class Bool {
   method pick() {
     defined self ?? self !! (True, False).pick
   }
 }

In fact, I see no reason not to patch Rakudo itself with this method for the time being.

--
Mark J. Reed <markjreed@​gmail.com>

@p6rt
Copy link
Author

p6rt commented Jul 1, 2010

From lembark@wrkhors.com

On Mon, 28 Jun 2010 08​:13​:21 -0700
"Patrick R. Michaud via RT" <perl6-bugs-followup@​perl.org> wrote​:

For a wide variety of reasons, Rakudo currently implements Bool as a
fundamental type rather than an enumeration. As such, Bool.pick is
acting the same as if one had written "Int.pick" or "Num.pick" -- it's
treating the invocant as a list of one element and then returning the
type object directly. And Bool as a type object always returns false
because it is undefined.

Q​: Why would the object type be false?

I would have thought that

  Bool.pick and print for ^100

turning into

  'Bool' and print for ^100;

would print all of the values, rather than printing
none of them (admittedly given only one day of Damian's
P6 class this assumption may be waaaay off).

For now, the workaround is to do (False,True).pick until we can properly
implement .pick on enumerations, and figure out how to turn Bool into
one (or convince the specification that Bool is not really an
enumeration :-).

Actually ^2.pick works nicely also, just seemed
odd that Bool.pick didn't.

thanx

--
Steven Lembark 85-09 90th St.
Workhorse Computing Woodhaven, NY, 11421
lembark@​wrkhors.com +1 888 359 3508

@p6rt
Copy link
Author

p6rt commented Dec 10, 2010

From @thundergnat

Tested on Rakudo 2010.11
This is Rakudo Perl 6, version 2010.11 built on parrot 2.10.1
RELEASE_2_10_1-679-g9bec614

Works correctly now.

perl6 -e "say Bool.pick for ^10;"
Bool​::True
Bool​::False
Bool​::True
Bool​::True
Bool​::False
Bool​::False
Bool​::False
Bool​::False
Bool​::True
Bool​::True

@p6rt
Copy link
Author

p6rt commented Jan 9, 2011

From @moritz

Works now, and is tested in S32-list/pick.t

@p6rt
Copy link
Author

p6rt commented Jan 9, 2011

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

@p6rt p6rt closed this as completed Jan 9, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant