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

Re: more ~~ concerns: object ~~

Thread Previous | Thread Next
Larry Wall
January 3, 2008 10:46
Re: more ~~ concerns: object ~~
Message ID:
On Fri, Dec 28, 2007 at 06:41:33AM -0500, Ricardo SIGNES wrote:
: * Ricardo SIGNES <> [2007-12-28T05:50:28]
: > If I ever decide that ~~ is something I want to use a lot, I expect to write a
: > little bit of sugar:
: > 
: >   use overload::match::as 'string';
: > 
: > ...which will always make the object ~~ as its string representation, to save
: > writing a noisier ~~ sub.  You could overload match as number, string, any
: > ref,
: Don't be silly.  Because ~~ is symmetrical, there's nothing to it:

Please note that we decided a year ago that Perl 6's ~~ must *not*
be symmetrical.  Even with Perl 6's type system, a symmetrical ~~
is Bad News, completely unpredictable and unoptimizable.  The nature
of the match is now determined *only* by the right argument (which,
if it chooses, can pay attention to the type of the left argument).
Without that kind of assurance, you can't even reliably optimize

    given $whoknowswhat {
	when 0 {...}
	when 1 {...}
	when 2 {...}
	when 3 {...}

into a jump table!  The dynamic type system of Perl 5 only exacerbates
this problem (see discussion in another thread of the effect of ==
on ~~, for instance).  In the current Perl 6 design, smart matching is 
really a convenient way to do a dispatch on the right argument rather
than the left, and every type that cares knows how to be a "pattern".

Another refactoring that seems to have fallen through the cracks is that
arrays no longer assume "any" semantics, because then there's no way
to match arrays as arrays.  So you have to be explicit about matching
junctionally if that's what you want.

I'm sorry these old misfeatures of the early Perl 6 design slipped
out into Perl 5 while I wasn't looking, but I'm only one person,
stretched far too thin these days, and I assumed that some subset of
p5p folk would gladly track the ongoing p6 design to extract out the
*principles* that are back-portable to Perl 5, not just the features.
In retrospect this seems not to have been a good assumption, and I
should have been more aware of the natural cultural bias against it.


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