Fixing const arrays
Jonathan M Davis
jmdavisProg at gmx.com
Sat Dec 10 14:37:48 PST 2011
On Sunday, December 11, 2011 07:31:28 kenji hara wrote:
> Treating whole constant arrays as ranges by automatically shedding the
> top-level const is good.
> But realizing it by language semantic change is definitely bad.It
> breaks IFTI rule, and adding special case will make difficult to learn
> language.
>
> Instead of language change, we can add specializations that receive
> non-ranges and convert them to ranges by removing top-level const.
> I believe that it is Phobos issue and is never the issue of language.
Making the fix in Phobos is a pain in that you have to duplicate functions all
over the place (though they'd just be wrappers, so you wouldn't have to
duplicate their implementations). And everyone who defines their own range-
based functions have to do the same thing.
The question is whether we actually lose anything by making it so that so that
IFTI won't give you a fully immutable or const array. And I don't see anything
that you'd lose or how it could break any code. Sure, it then becomes possible
to alter the array within the function where it wasn't before, but if it
couldn't before, making it possible now won't break anything, since the
function would have to be changed to even try. And for new functions, if they
_really_ want the array to be const or immutable, they can assign it to a new
array locally. I don't see how any expressiveness is really lost here or that
anything would be broken.
So, while this _does_ change the language's semantics, it seems to me that it
just changes them for the better, not worse.
Making this sort of change for static arrays _would_ be a problem, but I don't
see how it's an issue for dynamic arrays.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list