www.digitalmars.com         C & C++   DMDScript  

D - [Bug?] T[] ~= T vs. T[] ~ T

reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Using DMD 0.81, Windows 98SE.

It isn't clear from the spec which concatenation operations are actually 
supposed to be supported.

Given a type T, there are four possibilities:

(a) T[] ~ T[]
(b) T[] ~ T
(c) T[] ~= T[]
(d) T[] ~= T

My experiments have shown that all but (b) work.  For example, this 
compiles:

----------
int main() {
	char[] x = "abc";
	x ~= x[1];
	x ~= 'x';

	return 0;
}
----------

but this doesn't:

----------
int main() {
	char[] x = "abc";
	char[] y = x ~ x[1] ~ 'x';

	return 0;
}
----------

D:\My Documents\Programming\D\Tests\bugs\charcat.d(3): incompatible 
types for ((x) ~ (cast(int)(x[1]))): 'char[]' and 'int'

Is this supposed to happen?  It seems just plain inconsistent from where 
I am, and I can't see any reason that this shouldn't be allowed.

Stewart.

-- 
My e-mail is valid but not my primary mailbox, aside from its being the 
unfortunate victim of intensive mail-bombing at the moment.  Please keep 
replies on the 'group where everyone may benefit.
Mar 29 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Stewart Gordon wrote:

 Using DMD 0.81, Windows 98SE.

 It isn't clear from the spec which concatenation operations are 
 actually supposed to be supported.

 Given a type T, there are four possibilities:

 (a) T[] ~ T[]
 (b) T[] ~ T
 (c) T[] ~= T[]
 (d) T[] ~= T

 My experiments have shown that all but (b) work.  For example, this 
 compiles:

 ----------
 int main() {
     char[] x = "abc";
     x ~= x[1];
     x ~= 'x';

     return 0;
 }
 ----------

 but this doesn't:

 ----------
 int main() {
     char[] x = "abc";
     char[] y = x ~ x[1] ~ 'x';

     return 0;
 }
 ----------

 D:\My Documents\Programming\D\Tests\bugs\charcat.d(3): incompatible 
 types for ((x) ~ (cast(int)(x[1]))): 'char[]' and 'int'

 Is this supposed to happen?  It seems just plain inconsistent from 
 where I am, and I can't see any reason that this shouldn't be allowed.

 Stewart.
Yes it is. You can't append a character (or whatever) on to an array. You must append an array on to an array. -- -Anderson: http://badmama.com.au/~anderson/
Mar 29 2004
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
J Anderson wrote:

 Stewart Gordon wrote:
 
 Using DMD 0.81, Windows 98SE.

 It isn't clear from the spec which concatenation operations are 
 actually supposed to be supported.

 Given a type T, there are four possibilities:

 (a) T[] ~ T[]
 (b) T[] ~ T
 (c) T[] ~= T[]
 (d) T[] ~= T

 My experiments have shown that all but (b) work.
<snip>
 Yes it is.  You can't append a character (or whatever) on to an array.  
 You must append an array on to an array.
What has that to do with the fact it works with ~= ? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Mar 29 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Stewart Gordon wrote:

 J Anderson wrote:

 What has that to do with the fact it works with ~= ?

 Stewart.
It's not a bug its by design. However it would be nice to have the ability to append an element on to an array like you suggest. The ~= works, but the ~x[1] in my opinion is a consistency problem but not a bug. -- -Anderson: http://badmama.com.au/~anderson/
Mar 29 2004
next sibling parent reply C <dont respond.com> writes:
Inconsitency is a bug to me,

And this still works

int [] x;
x ~=3D 3;

but not this ?

char [] x;
x ~=3D 'Y';


C

On Mon, 29 Mar 2004 22:34:21 +0800, J Anderson =

<REMOVEanderson badmama.com.au> wrote:

 Stewart Gordon wrote:

 J Anderson wrote:

 What has that to do with the fact it works with ~=3D ?

 Stewart.
It's not a bug its by design. However it would be nice to have the =
 ability to append an element on to an array like you suggest.  The ~=3D=
=
 works, but the ~x[1] in my opinion is a consistency problem but not a =
 bug.
-- = D Newsgroup.
Mar 29 2004
parent C <dont respond.com> writes:
Ugh, im suffering from not reading enough lately.  ( Didnt read entire =

first post ).

Just ignore me.

C

On Mon, 29 Mar 2004 11:33:59 -0800, C <dont respond.com> wrote:

 Inconsitency is a bug to me,

 And this still works

 int [] x;
 x ~=3D 3;

 but not this ?

 char [] x;
 x ~=3D 'Y';


 C

 On Mon, 29 Mar 2004 22:34:21 +0800, J Anderson =
 <REMOVEanderson badmama.com.au> wrote:

 Stewart Gordon wrote:

 J Anderson wrote:

 What has that to do with the fact it works with ~=3D ?

 Stewart.
It's not a bug its by design. However it would be nice to have the =
 ability to append an element on to an array like you suggest.  The ~=3D=
=
 works, but the ~x[1] in my opinion is a consistency problem but not a=
=
 bug.
-- = D Newsgroup.
Mar 29 2004
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
J Anderson wrote:

 Stewart Gordon wrote:
 
 J Anderson wrote:

 What has that to do with the fact it works with ~= ?
It's not a bug its by design.
OK, so what bit of the spec have you found that I haven't? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Apr 01 2004