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

Re: disabling smartmatch and when()?

Thread Previous | Thread Next
Paul "LeoNerd" Evans
June 24, 2022 15:12
Re: disabling smartmatch and when()?
Message ID:
On Fri, 24 Jun 2022 10:07:25 -0400
"Ricardo Signes" <> wrote:

> On Tue, Jun 21, 2022, at 04:45, Paul "LeoNerd" Evans wrote:
> > I think there's two things we need to do:
> > 
> > 1) Make ~~ and given/when much louder about their "you shouldn't use
> >     this for new code" status;  
> Agreed.  Let's do that immediately?

Righty. I'll see what I can hack up.

> > 2) Create a better replacement  
> I'm all for having a better replacement, but I continue to strongly
> oppose the idea that we *need* one to remove the old thing.
> A replacement would be nice, if it's good, but it doesn't need to
> exist before we take the old thing out.

Agree - these are two separate things. We can do them independently.

> I write a lot of Perl, and have since before smartmatch was
> introduced.  I never used smartmatch for much.  I have banned it from
> my projects.  I have seen it largely unused.  Nothing it does can't
> be done some other way already, although sometime more verbosely.  We
> don't need a replacement, because *we have gotten along fine without
> using it for 20 years.*

Yah I'm inclined to agree. But also we're honestly most of the way
there in terms of designing nicer replacements.

Most of the weird funky cases of the ~~ operator (e.g. the array
distributative nature of  $str ~~ @arr) can be handled with things like
List::Util::all - of which I hope to have a nicer core syntax soon.
Plus once I finish working out how to do parametric syntax using
XS::Parse::Infix, I'll have the `in<eq>` and `in<==>` operators. For
now there's `$str elem @arr_of_strings` and `$num ∈ @arr_of_nums`
operators (yes the latter requires UTF-8, because I couldn't find a
free sequence of ASCII symbols that makes sense) provided by
Syntax::Operator::Elem (which I really should get onto CPAN soon).

Most of the simpler uses of given/when are just as tidy with my
match/case syntax, provided by Syntax::Keyword::Match. It's an evolving
design that I hope to drag into core sometime, much like the design
process that lead to try/catch in core.

Paul "LeoNerd" Evans      |  |

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