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

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

Thread Previous | Thread Next
From:
Jesse Luehrs
Date:
August 24, 2012 06:00
Subject:
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
20120824130020.GF11137@tozt.net
On Fri, Aug 24, 2012 at 02:51:35PM +0200, Leon Timmermans wrote:
> On Fri, Aug 24, 2012 at 3:08 AM, Damian Conway <damian@conway.org> 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.

-doy

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