develooper Front page | perl.perl5.porters | Postings from June 2012

Re: Smartmatch two cents (was... List::Util... when...)

Thread Previous | Thread Next
From:
Klaus
Date:
June 29, 2012 12:17
Subject:
Re: Smartmatch two cents (was... List::Util... when...)
Message ID:
7d36088c-6f7a-4cc0-ac89-b446c0d9fb27@f30g2000vbz.googlegroups.com
On 29 juin, 12:54, e...@waniasset.com (Ed Avis) wrote:
> Father Chrysostomos via RT <perlbug-followup <at> perl.org> writes:
>
> >Oh, and let’s deprecate smartmatch while we are at it.
>
> I agree, and for the one case where smartmatch is useful in practice:
>
>     if ($x ~~ @values) { ... }
>
> add a new operator 'in' borrowed from Python
>
>     if ($x in @values) { ... }
>
> which does an 'eq' comparison with each item in the list, stopping and returning
> true if one matches, false otherwise.
>
> I would gladly remove smartmatch from my code if Perl provided an 'in' keyword
> to replace it, which is the only thing I use smartmatch for anyway.

I agree with your statement, but the problem is that there is always
something to be added, for example: what about numeric values ? --> so
it seems reasonable to add an '==' comparison for numeric values, but
hey, we also want text that looks like a number to be treated like a
number, so we add '==' comparison for that, too, and so on...

...so we finally arrive at the same mess with 'in' as we already have
with ~~.

Maybe two versions of 'in' might be in order, 'in_eq' for text
comparison and in_== for numeric comparison. But again, there is
probably a better way...

You see, it never stops.


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