develooper Front page | perl.perl6.language | Postings from July 2010

Re: Smart match isn't on Bool

Thread Previous | Thread Next
From:
Patrick R. Michaud
Date:
July 31, 2010 11:47
Subject:
Re: Smart match isn't on Bool
Message ID:
20100731184749.GA351@pmichaud.com
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...

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

Pm

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About