More D newb questions.

Me Here p9e883002 at sneakemail.com
Mon May 5 12:09:24 PDT 2008


BCS wrote:


> for one thing "abcd[b1]" is not a slice, if you want a slice use
> "abcd[b1..b1+1]"

Yeah. Its just another tacky inconsistancy.


int main( char[][] args ) {
    char[] a = "x";
    char b = 'x';
    writefln( a ~ b );
    writefln( a );
//    writefln( b ~ b );
    return 1;
}
ouputs:

xx
x

So, D knows how to concatenate a single character char[] with a char 
and produce an intermediate result. Ie. The char[] isn't mutated.

But uncomment the line that attempts to concatenate char to char, and you get:

    junk.d(8): Error: Can only concatenate arrays, not (int ~ int)

which is silly. There's no technical reason for not allowing this. 
And there's no semantic reason either. 
What elese could 'a' ~ 'b' mean other than char[] tmp = "ab"?

Similarly, there's no technical reason for not allowing 
lvalue slice assignments to grow or shrink the target,
or do overlapping copies. 

Such things are relatively trivial to write and are a part of library.
But every programmer having to write their own code to detect
whether the source and target of slice assignments are different
sizes, or overlap, at each site and decide whether they can use a 
slice assignment or must revert to calling a library function 
is a nonsense.

D's built-in string handling is rapidly loosing it shine for me :(

b.
-- 




More information about the Digitalmars-d mailing list