HaloO, On Saturday, 31. July 2010 20:47:49 Patrick R. Michaud wrote: > On Sat, Jul 31, 2010 at 10:56:47AM -0600, David Green wrote: > > It's not unreasonable, especially if that's what you expect. > > But it's even more reasonable to expect this to work: > > given $something { > > when True { say "That's the truth!" } > > when 42 { say "Good answer!" } > > when "viaduct" { say "You guessed the secret word!" } > > } > > I'm not so sure about this. There's an argument to be made that > the C<when 42> and C<when "viaduct"> cases should never be reachable, > since both C<42> and C<"viaduct"> are considered "true" values...
Sorry, I don't understand this possible argument. Isn't the intent of a given/when to select one alternative by means of the given? This is what a switch statement does. Perl 6 allows non-constants after when, so it's reasonable to have the constant in the given and to see e.g. which function returns it. Of course the first actually doing this determines the switch. > ... unless you want C<when True> to do a value-and-type check, > in which case it doesn't exactly follow the pattern for smartmatching > of the other builtin types (which only check value equivalence, > not type equivalence). This is true only if you want to distinguish 1 and True which are the same value. But 42 should be distinct from this. Same goes for "viaduct". So these three should be a valid disjoint set of choices that can be made given $something. Regards, TSa. -- "The unavoidable price of reliability is simplicity" -- C.A.R. Hoare "Simplicity does not precede complexity, but follows it." -- A.J. Perlis 1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan