develooper Front page | perl.perl5.porters | Postings from June 2022

Re: Pre-{Pre-RFC} - match/case syntax

Thread Previous | Thread Next
Darren Duncan
June 27, 2022 20:45
Re: Pre-{Pre-RFC} - match/case syntax
Message ID:
On 2022-06-27 6:12 a.m., Martijn Lievaart wrote:
> Op 27-06-2022 om 11:14 schreef Paul "LeoNerd" Evans:
>> On Mon, 27 Jun 2022 02:11:08 -0700
>> Darren Duncan <> wrote:
>>> This should be generic and configurable in the same way map/grep/sort
>>> etc are.
>> I'm not sure I follow this bit. How are those configurable now?
>> Can you suggest some examples?
> Map/grep/sort can take a sub which does the comparison/filter. Darren makes a 
> good observation that that is actually quite similar to your proposed 
> match/case, where you give the operator.

Martijn is spot on as to what I meant, as stated above.

> I think what Darren means is that it 
> may make sense to think about both extending your proposal to sort and friends 
> and apply a more generic approach to match/case:
>      @x = sort : <=> @x; # we need a better syntax than this

I actually was NOT suggesting that sort and friends are altered in any way, not 
that extending them would necessarily hurt, but rather that sort and friends can 
be used as inspiration for the new match feature.

> and a generic comperator to match/case:
> match ($n : sub($a, $b) { $a==$b })
>        case(1) { say "It's one" }
>        case(2) { say "It's two" }
> ...

Yes, this above example is exactly what I had in mind about generic and 

Having the shorthand of "==" in place of the sub for common scenarios is also 
nice, but the general form like above is what's most important if the feature 
itself wants to keep things simpler.

-- Darren Duncan

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About