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-follo...@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 <markjr...@gmail.com>