develooper Front page | perl.perl5.porters | Postings from September 2012

Re: fixing smartmatch just hard enough (and when, too)

Thread Previous | Thread Next
Aaron Priven
September 5, 2012 16:33
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
On Sat, Sep 1, 2012 at 8:43 AM, Ricardo Signes <>wrote:

> * Leon Timmermans <> [2012-09-01T10:44:44]
> > On Sat, Sep 1, 2012 at 4:33 PM, Aaron Priven <> wrote:
> > > is it possible to add a binary infix operator in a Perl 5 module?
> >
> > I don't think so

> That is also my understanding: it would be great if it existed and worked,
> but
> it doesn't, and would be hard to make happen.

OK, that's what I thought.

I don't remember ever using ~~ except in the "$scalar ~~ @array" sense,
which provides a simple infix operator in core perl for what seems to me to
be a really common, simple function: is such-and-such an element of this

The proposal takes that away, and replaces it with "$scalar eq any(@array)"
-- where "any" creates a junction.

That's not a lot more characters, of course, but it is some. And while some
people may think naturally "is this thing equal to any of the members of
this other thing?", I suspect it's a lot more natural for people to think
"is this thing in this container?"

I don't know what I think of the rest of the smartmatch discussion. I'm
pretty sure I would never use the limited smartmatch being discussed, but
that's not an argument against it. But I do think simple replacements for
what are smartmatch's common uses today would be good to have.

I think, even if it's implemented in terms of junctions, having a binary
"in" operator would be easier for people to understand and a worthy
addition to the Perl language. And one that, clearly, cannot be tried out
as a module.

Aaron Priven,

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