develooper Front page | perl.perl5.porters | Postings from September 2015

Re: smartmatch needs your eyes

Thread Previous
From:
Paul "LeoNerd" Evans
Date:
September 10, 2015 16:30
Subject:
Re: smartmatch needs your eyes
Message ID:
20150910173026.7f9fab24@shy.leonerd.org.uk
On Thu, 10 Sep 2015 18:10:11 +0200
"H.Merijn Brand" <h.m.brand@xs4all.nl> wrote:

> On Thu, 10 Sep 2015 16:58:02 +0100, "Paul \"LeoNerd\" Evans"
> <leonerd@leonerd.org.uk> wrote:
> 
> > On Thu, 10 Sep 2015 17:42:24 +0200
> > "H.Merijn Brand" <h.m.brand@xs4all.nl> wrote:
> > 
> > >     $x ~~ 42        -->     $x == 42        ???
> > >     $x ~~ "foo"     -->     $x eq "foo"     ???  
> > 
> > I expect not.
> > 
> >    my $x = 1;
> > 
> >    $x ~~ "1.0"
> > 
> > does what? It's this "try to guess from many possible types of
> > match" that is deemed the core problem of
> > toosmartforitsowngood-match in the first place.
> 
> If the case was keep it simple, your example would fail, as
> 
>   $x ~~ "1.0"  => 1 eq "1.0" which is false, and I would accept that
> 
> your case would be valid for
> 
>   $x ~~ 1.0    => 1 == 1.0 
> 
> where it would match, and again I tend to agree

Ah; the point of my email was to suggest that the omission of an eq- or
==-alike case might be intentional. If the mere syntax of trying to
smartmatch against a string or number literal is *already* a syntax
error, then nobody needs to think through the cornercases of what kinds
of value might or might not match at runtime. Such a program won't
compile.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
http://www.leonerd.org.uk/  |  https://metacpan.org/author/PEVANS

Thread Previous


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