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

Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]

Thread Previous | Thread Next
From:
Salvador Fandino
Date:
October 13, 2015 13:25
Subject:
Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]
Message ID:
561D0627.6050203@gmail.com
On 10/07/2015 10:24 AM, Dave Mitchell wrote:

>
> I think 95% of what people actually *want* a smartmatch system for is so
> that they can write code of one of these three forms:
>
>      given ($index) {
>          when (undef)     {...}
>          when (0)         {...}
>          when (1)         {...}
>          when (INDEX_MAX) {...}
>      }
>
>      given ($string) {
>          when (undef) {...}
>          when ("foo") {...}
>          when ("bar") {...}
>          when (BAZ)   {...}
>      }

Lets for a moment forget about the smart match operator and focus on when.

My understanding is that the issue there is really reduced to the 
incapability to determine if the user wants number or string equality so 
well, let him tell perl what he wants in a concise way, using '+' (or '-'):

given ($index) {
     when (undef)      # !defined
     when (+1)         # ==
     when (+INDEX_MAX) # ==
     when (+"foo")     # ==
     when (-1)         # ==
     when (3)          # eq? I am undecided about literal numbers
     when ("foo")      # eq
     when (BAZ)        # eq
     when (/$re/)      # /$re/
}




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