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

Re: fixing smartmatch (again (still))

Thread Previous | Thread Next
David Golden
August 28, 2012 14:00
Re: fixing smartmatch (again (still))
Message ID:
On Tue, Aug 28, 2012 at 2:43 PM, Ricardo Signes

>   given ($x) {
>     when ($y)  { ... } # $x ~~ $y
>     when (4)   { ... } # $x == 4
>     when ('4') { ... } # $x eq 4
>   }
> Deferred/computed values of any sort mean smart match.
> Two dead-simple special cases: Numeric literals mean ==.  String literals
> mean
> eq.

I agree this solves many of the technical issues raised, but I fear that
it's going to confuse some people or mis-set expectations.

* Currently when() does smartmatch, so you have to retrain people not to
think of when() as smartmatch, but to think of when() as a "smart switch"
or something.

* You can test a value with when() that you can't smartmatch, so if people
don't internalize that when() is no longer smartmatch, at some point
they'll smartmatch a literal and expect it to work like when.

Since smartmatching a literal isn't ambiguous, I think that it would be
less confusing to just add literals to the smartmatch table and let when()
stay as smartmatch.  That means *one* big change instead of two.

FWIW, I would still like "when {...} {...}" as a shorter way to write "when
(sub{...}) {...}", but think that's "nice to have" and not necessary for
fixing smartmatch.


*David Golden* <>
*Take back your inbox!* →
Twitter/IRC: @xdg

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About