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

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

Thread Previous | Thread Next
From:
Damian Conway
Date:
August 22, 2012 16:48
Subject:
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
CAATtAp7Sy4+XyOOkc9L3mk9OayqRk5Qq5jUenWhDa4MgSJokWg@mail.gmail.com
Jesse Luehrs suggested:

> So maybe what we really want is to move that case down below the "Any ->
> Code" case.

I don't think so. If overloading is tested first, then the overloading
itself can implement
a fallback to the standard Any ~~ CodeRef case.

If Any ~~ CodeRef is tested first, then new classes have no way to
intercept and
control that behaviour sensibly for their objects.

In fact, I would argue that the overloading case should come *first*
in the table,
even before the Any ~~ undef case, so that classes overloading smartmatch can
intercept and handle that case too.


> If $b is a coderef, I'd expect it to be called with the junction,
> rather than calling the ~~ overload on the left hand side.

So what if I want *correct* junctive behaviour in that case: namely that
each element of the junction is distributed over a separate call to the sub
and the results are rejunctified.

You're proposing that:

    any(9,10,11) ~~ \&is_prime

be equivalent to:

   is_prime(any(9,10,11))

but what if I want it to mean what it's supposed to mean:

   any(is_prime(9), is_prime(10), is_prime(11))

If overload testing comes first, I can implement the Junction class's
overloading to do that. If CodeRef testing comes first, I'm screwed.

Damian

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