More D newb questions.

Derek Parnell derek at psych.ward
Mon May 5 15:21:58 PDT 2008


On Mon, 05 May 2008 13:58:16 -0700, BCS wrote:


> based on what you ask for this would be valid
> 
> char[] a, b;
> char[][] c = a ~ b; // ok
> char[]   d = a ~ b; // same expression, different type?
> auto     e = a ~ b; // what's the type of this then?

It would be 'char[]' of course, because 'a' is char[]. The convention for
the determining the 'auto' type based on the first identifier is already an
established concept in D.
 
> but for that to work you would need to look up and down the expression 
> tree just to figure out what something is. That gets just plain nasty.
> 
>> 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. 
> 
> I think there is a reason for it. D is a low level language, the 
> semantic you are asking for can be done in a function and, if included 
> in a language, would hide some types of errors. IMHO D should not have 
> any semantics that are not easy for the program to understand how they 
> are working.
> 
> for example, If I understand you correctly you would like this to work:
> 
> char[] t = "hello world";
> auto u = t;
> auto v = u[8];
> t[5..5] = ",";
> 
> assert(t == "hello, world");

Huh? Why would the length change? t[5..5] = "," should fail because the
left and right sides of the assign are different lengths.

> 
> IIRC the reason that overlapping copies are not allow is that the 
> overhead of checking them is non trivial and the code to do the copy is 
> to. 

And yet D fails at runtime if you attempt an overlap so it must already be
doing such checking.

> D is taking the approach of "most copies are never overlapping and 
> if you need might need it say so" In a higher level language this would 
> be a problem, but for what D is intended for, this isn't a problem.

Is D not trying to also become a multi-paradigm language. Not many people
would suggest that a functional language is a 'low-level' language.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list