Const, invariant, strings and "constant data need never be copied"

Janice Caron caron800 at googlemail.com
Sat Nov 3 07:21:49 PDT 2007


On 11/3/07, Stewart Gordon <smjg_1998 at yahoo.com> wrote:
> So effectively, you're using the word "string" to refer specifically to the
> invariant kind, making "if all strings are invariant" a null condition.

Well, it is now. :-)

I guess I should have clarified that all my strings were immutable
even back when string was const(char)[].


> So in other words, my code was more or less right in the first place.

Basically, yes. /Except/ in your expectations of std.string. The
functions in std.string are for fully constructed strings, not for
strings-under-construction. I'll get back to that in a minute.

> > Then you shouldn't be calling std.string functions. What you need are
> > array functions.
>
> I'm not sure what you mean....

I suppose I'm saying we need some extra functions. Maybe even a
library std.array. (It's not a big deal as it's relatively easy to
write these things yourself). But for functionality like in-place
replace, we should be using some specialized function like (if it
existed) std.array.replace - but definitely not std.string.replace.
Have you ever programmed in PHP? I'd like to see (almost) all the PHP
array functions available as standard in D. That way, it would be so
much easier to build char arrays in the manner that you suggest, and
then turn them into strings when they're fully built.

See http://uk2.php.net/manual/en/ref.array.php



More information about the Digitalmars-d mailing list