Principled method of lookup-or-insert in associative arrays?

Tomek Sowiński just at ask.me
Sat Nov 20 06:22:37 PST 2010


Dnia 20-11-2010 o 13:33:29 spir <denis.spir at gmail.com> napisał(a):

> I find this proposal really necessary. But aren't there two issues here?
> * Comparison (for lookup) by value equality should not care about  
> qualifiers (ie compare raw content, here plain array memory areas).
> * Assignment should perform "qualification conversion" automatically, eg
> 	char[] chars = "abc";
> 	string s = chars;
> This involves no implicit magic here, as target qualification is  
> explicit. So, why not?

It's busting the whole const system to smithereens.

char[] chars = "abc";
char[] backdoor = chars;
string s = chars;
assert (s == "abc");
backdoor.front = 'k';
assert (s == "abc"); // fails. not so immutable, huh?

> There is a repetitive programming pattern in D:
> * play around with *string's in general
> * as soon as text processing is needed, convert to *char[]
> * when finished, convert back to *string

Meh, immutable strings make life easier.

-- 
Tomek


More information about the Digitalmars-d mailing list