Principled method of lookup-or-insert in associative arrays?
Pelle Månsson
pelle.mansson at gmail.com
Sat Nov 20 09:38:54 PST 2010
On 11/20/2010 05:09 PM, spir wrote:
> ???
> backdoor and s do not denote the same element. One is a mutable array, the other is immutable. Why should changing backdoor affect s? Whether backdoor and chars denote the same array depends on whether "=" copies or not dyn arrays. But from immutable string to mutable array, there must be a copy (read: dup).
Must also be a copy the other way. Secret heap allocations are not fun.
> Anyway, the most annoying issue is not about assignments inside a given scope, but parameter passing (including implicit ones like in Andrei's example of foreach).
> void f (char[] chars) {}
> void g (string str) {}
> ...
> string str = "abc";
> char[] chars = "abc".dup;
> f(str);
> g(chars);
> __trials__.d(30): Error: function __trials__.f (char[] chars) is not callable using argument types (string)
> __trials__.d(31): Error: function __trials__.g (string str) is not callable using argument types (char[])
> ...
> f(str.dup); // ok
> g(chars.idup); // ditto
>
I do not understand the alternative.
>
> By the way, why isn't the definition of string immutable(char[]), instead of immutable(char)[]?
>
string s = "abc";
s = "bde"; // fails with immutable(char[]), rightly so.
More information about the Digitalmars-d
mailing list