www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - A array bug?

reply taqya <taqya9 gmail.com> writes:
Hi,i write this code. then d compiler is shutdown.
Is it a array bug?

//Digital Mars D Compiler v2.014 (windows)
import std.stdio;
int main()
{
	char[] a = "a".dup;
	char[] b = "b".dup;
	writefln(a + b); //Error: Array operations not implemented
	return 0; 		 
}
Jan 28 2009
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
taqya wrote:
 Hi,i write this code. then d compiler is shutdown.
 Is it a array bug?
 
 //Digital Mars D Compiler v2.014 (windows)
 import std.stdio;
 int main()
 {
 	char[] a = "a".dup;
 	char[] b = "b".dup;
 	writefln(a + b); //Error: Array operations not implemented
 	return 0; 		 
 }
'+' implies you're trying to add "a" and "b" together e.g. (char)((int) 'a' + (int) 'b') If so, the error informs you why you can't do that. If you're trying to concatenate, use the '~' operator. assert ( "a" ~ "b" == "ab" );
Jan 28 2009
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Ellery Newcomer wrote:
 taqya wrote:
<snip>
     char[] a = "a".dup;
     char[] b = "b".dup;
     writefln(a + b); //Error: Array operations not implemented
<snip>
 If so, the error informs you why you can't do that.
<snip> Except that it doesn't. "Array operations not implemented" is a leftover from a previous version of the D spec. Nowadays array operations _are_ implemented, but the language doesn't support this particular use thereof. So the bug is that the error message is badly written. Stewart.
Feb 04 2009
parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Stewart Gordon wrote:
 Ellery Newcomer wrote:
 taqya wrote:
<snip>
     char[] a = "a".dup;
     char[] b = "b".dup;
     writefln(a + b); //Error: Array operations not implemented
<snip>
 If so, the error informs you why you can't do that.
<snip> Except that it doesn't. "Array operations not implemented" is a leftover from a previous version of the D spec. Nowadays array operations _are_ implemented, but the language doesn't support this particular use thereof. So the bug is that the error message is badly written. Stewart.
Suggest: Array operation '<OP>' not implemented for type <T>[]. Where <OP> is here '+' and <T> is here char. And possibly catch the particular case of char[] and suggest '~', since it is probably the single most common mistake in this area. -- Chris Nicholson-Sauls
Feb 05 2009
next sibling parent taqya <taqya9 gmail.com> writes:
Chris Nicholson-Sauls Wrote:

 Stewart Gordon wrote:
 Ellery Newcomer wrote:
 taqya wrote:
<snip>
     char[] a = "a".dup;
     char[] b = "b".dup;
     writefln(a + b); //Error: Array operations not implemented
<snip>
 If so, the error informs you why you can't do that.
<snip> Except that it doesn't. "Array operations not implemented" is a leftover from a previous version of the D spec. Nowadays array operations _are_ implemented, but the language doesn't support this particular use thereof. So the bug is that the error message is badly written. Stewart.
Suggest: Array operation '<OP>' not implemented for type <T>[]. Where <OP> is here '+' and <T> is here char. And possibly catch the particular case of char[] and suggest '~', since it is probably the single most common mistake in this area. -- Chris Nicholson-Sauls
import std.stdio; void main() { char[] a = "a".dup; char[] b = "b".dup; writefln(a+b); } I compile the code on Windows. Then pop up a message 'dmd.exe has stopped working'. my personal situation?
Feb 05 2009
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Chris Nicholson-Sauls wrote:
<snip>
 Suggest: Array operation '<OP>' not implemented for type <T>[].
 
 Where <OP> is here '+' and <T> is here char.
It doesn't quite work like that. AIUI the only supported way of using array operations is assigning the result to an array slice, which this isn't.
 And possibly catch the particular case of char[] and suggest '~', 
 since it is probably the single most common mistake in this area.
Maybe.... Stewart.
Feb 05 2009
parent Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Stewart Gordon wrote:
 Chris Nicholson-Sauls wrote:
 <snip>
 Suggest: Array operation '<OP>' not implemented for type <T>[].

 Where <OP> is here '+' and <T> is here char.
It doesn't quite work like that. AIUI the only supported way of using array operations is assigning the result to an array slice, which this isn't.
Just double-checked the spec, and yes, array ops are triggered by a slice appearing as an lvalue. So, a different error message entirely is warranted. -- Chris Nicholson-Sauls
Feb 05 2009