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

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

Thread Previous | Thread Next
Jesse Luehrs
August 24, 2012 06:00
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
On Fri, Aug 24, 2012 at 02:51:35PM +0200, Leon Timmermans wrote:
> On Fri, Aug 24, 2012 at 3:08 AM, Damian Conway <> wrote:
> > In other words, every single time an object is the LHS operand of a
> > smartmatch, we need (at least the option) to be able to have that object
> > decide how the match should work.
> I guess. Conceptually left handed matching and right handed matching
> feel like completely different, because left hand is usually about the
> $self and right handed is about the $other, to the point where I'd
> almost suggest making them separate for purposes of operator
> overloading.

Yes, I think that at the very least we should do this. Almost nothing
makes sense to appear on both the left and right sides of a smartmatch
(junctions being the only exception I can think of). Smartmatch isn't
commutative, so every single smartmatch overload will need to look like

  sub {
      my ($left, $right, $swap) = @_;
      if ($swap) {
      else {

or else it will be pretty broken, so I think that should be enforced by
the overloading mechanism itself.


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