RE: join() and split() to respect string overload operations

[email protected] ("Jan Dubois")
Newsgroups perl.perl5.porters
Organization ActiveState Software Inc
Message-ID <[email protected]>
On Tue, 08 Jun 2010, Paul LeoNerd Evans wrote:
> On Mon, Jun 07, 2010 at 09:03:18AM -0700, Jan Dubois wrote:
> > I don't quite get how this would not work as long as you also have a
> > well-behaved overload for 'eq' and '""'.

[...]
 
> > Or would these identities also be
> > broken:
> >
> >    substr( $str . "x", 0, len $str ) eq "$str"
> >    substr( "x" . $str, 0, 1 ) eq "$str"
> >
> >    substr( $str, 0, 1 ) . substr( $str, 1 ) eq "$str"
> >
> > If these work, but yours don't, then I wouldn't consider the complete
> > set of overloads to be self-consistent.  If the these later identities
> > are broken as well, could you give an example of how to do it?
> 
> But, these identities -are- broken, because of the "squashing to plain
> string" that happens on the right-hand side.

Ok, in that case I don't consider your "eq" overload to be well-behaved:

Any implementation that doesn't return a true value for

    $str eq "$str"

is broken and a misuse of the overload mechanism IMO because it no
longer preserves string semantics and should be implemented as a plain
method instead.

You are of course free to abuse the mechanism any way you want, but you
cannot really claim that join/split/substr don't respect string overloading
if you aren't doing it yourself properly either.

Cheers,
-Jan
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.