develooper Front page | perl.perl5.porters | Postings from December 2017

Re: Revisiting smart match

Thread Previous | Thread Next
From:
Dan Book
Date:
December 19, 2017 04:23
Subject:
Re: Revisiting smart match
Message ID:
CABMkAVV-bCfK-9S-yUoqPLam7GtF43oMVKmE+tLYF+L=Uz+PLw@mail.gmail.com
On Mon, Dec 18, 2017 at 11:12 PM, Karen Etheridge <perl@froods.org> wrote:

>
> On Mon, Dec 18, 2017 at 7:38 PM, Dan Book <grinnz@gmail.com> wrote:
>
>> The intent is that the two keywords will disambiguate `when`s currently
>> ambiguous behavior; it can either apply a smartmatch between its operand
>> and the topic, or it can test an expression for truthiness.
>>
> ‚Äč
> Why can't when_or_whatever_it_is(...) simply evaluate the expression
> inside, no matter what that expression is? Indeed I thought that's how it
> already worked (aside from the complicated ~~ behaviour).  The fact that
> the ~~ operator is changing at the same time is orthogonal:
>
>     given ($foo) {
>         when ($truthy) { ... }
>         when ($_ == 1) { ... }
>         when ($x == 1) { ... }                          # doesn't actually
> use $_; so what?
>         when ($_ eq 'hello world') { ... }
>         when ($_ ~~ $d) { ... }
>     }
>

That's precisely what one of the proposed keywords will do. However, a
large majority of given/when code in the wild uses when to implicitly
smartmatch so they don't have to write `$_ ~~`, so it's likely that people
will still want that ability, and this proposal is to continue supporting
that with another keyword.

-Dan

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