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

Re: Smart match isn't on Bool

Thread Previous | Thread Next
From:
Darren Duncan
Date:
July 31, 2010 16:55
Subject:
Re: Smart match isn't on Bool
Message ID:
4C54B7E1.9090502@darrenduncan.net
Brandon S Allbery KF8NH wrote:
> I think there's a confusion about what given/when is doing.  Naïvely(?), I
> expect it to be shorthand where the value for "when" is matched against the
> one for "given", thus your example would be (pseudocode) "if 0 == True" and
> expecting "OH NOEZ" *would* be unreasonable.
> 
> Is given/when trying to do too many things at once?

I would prefer if given/when was nothing more than an alternate syntax for 
if/then that does comparisons.  That is, these would be equivalent:

   given $foo {
     when $bar {...}
     when $baz {...}
     default {...}
   }

   if $foo eqv $bar {...}
   else if $foo eqv $baz {...}
   else {...}

On the other hand, Perl 6 has multiple equality comparison operators, eqv, eq, 
==, ===, etc, and hence ~~ semantics instead of eqv may seem to make some sense, 
though I think that would cause more problems.

So I think if given-when just used eqv semantics and then users explicitly 
coerced their arguments instead, that might be best.  For example, in the 
general case, say they want numeric semantics and the arguments aren't 
necessarily already numbers:

   given +$foo {
     when +$bar {...}
     when +$baz {...}
     default {...}
   }

All this being said, I really do *not* like the idea of saying Bool is just a 
subset of Int as it seems to be.  Bool should be disjoint from every other 
common type like Int/Str/etc instead.

Asking "False eqv 0" should be false, though either "False eqv ?0" or "+False 
eqv 0" being true is okay.

If people want ~~ semantics, let them ask for it explicitly, such as with:

   given $foo {
     when ~~ $bar {...}
     when ~~ $baz {...}
     default {...}
   }

-- Darren Duncan

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