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:
Abigail
Date:
October 13, 2015 13:42
Subject:
Re: YA smartmatch proposal [ was: Re: smartmatch needs your eyes]
Message ID:
20151013134212.GA7595@almanda.fritz.box
On Tue, Oct 13, 2015 at 03:24:55PM +0200, Salvador Fandino wrote:
> 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/
> }



Unary '+' already has a meaning (a no-op), and unary '-' has a
specific meaning as well (-"-foo" is the string "+foo" -- which for
literal strings is done at compile time).



Abigail

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