[Issue 7177] $ should forward to length by default

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 21 09:11:44 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=7177



--- Comment #20 from Steven Schveighoffer <schveiguy at yahoo.com> 2013-03-21 09:11:43 PDT ---
(In reply to comment #18)
> > That's a strong case. If compiler tries to translate $ to length
> > automatically, library AA implementation will become impossible.
> 
> That's not a problem at all. As long as the logic is that length is aliased to
> opDollar as long as opDollar isn't defined, then it won't break anything.
> Anything that needs to define opDollar differently will define opDollar, and
> for the rest, if they define length, then it gets aliased to opDollar. I really
> don't see the problem with that. And without this, requiring opDollar with
> hasSlicing will break tons of code.

The point of the AA example is that opDollar should be illegal, not that it
should map to something else.

I don't think we need to require opDollar with hasSlicing, why would you think
that?

(In reply to comment #19)
> Note though that opDollar would *fallback* to length if you did not implement
> opDollar. You are still free to implement your own opDollar if you wish, so
> your DCollections would still be fine.

My point is that I have to opt out of that behavior.  This means it breaks my
current code.

> No need! Please don't close it quite yet. A simple "@disable opDollar();" or
> "private opDollar();" should shut down this problem.

This is a good thing to bring up, but I don't really understand why opDollar
needs to be implemented by default.  It's only valid inside indexers, and only
makes sense for indexes that are integers, begin at 0, and end at .length. 
Isn't that a lot of assumptions to make for opIndex, which can take any type of
argument, and whose domain space can mean anything?  We can prove that a type
has indexing, that it has length, even possibly that it's indexer takes the
same type as length returns, but I think it's too assuming to guess at the
domain space of the index.

Why is it so bad to explicitly alias opDollar to length?  It seems we are using
anecdotal evidence (phobos requires a few aliases) to apply to all code in
existence and that ever will exist.  An alias consumes NO code space, it's
free.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list