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

Re: fixing smartmatch (again (still))

Thread Previous | Thread Next
From:
David Golden
Date:
August 28, 2012 14:00
Subject:
Re: fixing smartmatch (again (still))
Message ID:
CAOeq1c_=GfS05Pq7XotuGUUvNt7FdQeM1i-oUnYjot0n_gkTbw@mail.gmail.com
On Tue, Aug 28, 2012 at 2:43 PM, Ricardo Signes
<perl.p5p@rjbs.manxome.org>wrote:

>   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

-- 
*David Golden* <dagolden@cpan.org>
*Take back your inbox!* → http://www.bunchmail.com/
Twitter/IRC: @xdg

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