develooper Front page | perl.perl5.porters | Postings from December 2008

long-forgotten patch: tests for t/op/smartmatch.t

Thread Next
Ricardo SIGNES
December 30, 2008 16:11
long-forgotten patch: tests for t/op/smartmatch.t
Message ID:

Look, another patch from Yuval!  I promised I'd check this out, too, because we
all hate being unclear on the fuzzy-yet-sharp edges of ~~ and want to get the
damn thing into perfect awesomeness.

I heard a rumor that Yuval might be redoing these patches against git, to
follow up.

Actually, multiple patches.  They're in:

(By the way:  MarkMail is -so- good for finding this sort of thing!)

There are test improvements that I think are all a good idea.  Then there are
changes to the restriction on ~~-on-objects-without-~~-overloading.

(1) $obj ~~ $code should work

I agree... but not if the comment in perlsyn is true, "overloading trumps
everything."  Because the precedence table is or was based on the idea that the
lhs/rhs of the operator were positionally irrelevant, then this is very

  # without overloading
  $obj ~~ $code  :=  $code->($obj)

  # with overloading
  $obj ~~ $code  :=  $obj->~~($code)

Ugh!  We can't say that "you put the code on the left to ensure you call the
code" because the order is declared irrelevant.

This violates the "let people add ~~ later" rule (below).  I think that the
REAL fix is not to disallow $obj ~~ $code, but to say that /match against
Code[+]/ trumps everything.

(2) $obj_A ~~ $obj_B should check refaddr equality

I don't agree.  It means that if ref($obj_B) later wants to add ~~, having not
yet been updated to v10 features, it will break code that assumes that this is
true.  Part of the reason to require objects provide ~~ explicitly is to allow
~~ overloading to be added to existing classes without users of those classes
having relied on the "core" behavior of object overloading.

(2) $obj ~~ $str should mean $obj->isa($str)

No, for the same reasons.  As for exceptions, cited in the post, I think that
core 5.12 exceptions will just provide overloaded ~~ anyway which will check
for the exception's roles.

Anyway, we'd want it to call DOES, not isa, right?  Anyway, once somebody sees
that they can add ~~ to their old String::Matcher code to make it call the
->match method, things that expected ~~ to mean isa break.  Too much trouble.


The only relaxation I favor is that $obj ~~ $code always means $code->($obj),
and that code trumps overload.


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