Thread overview
[Bug?] T[] ~= T vs. T[] ~ T
Mar 29, 2004
Stewart Gordon
Mar 29, 2004
J Anderson
Mar 29, 2004
Stewart Gordon
Mar 29, 2004
J Anderson
Mar 29, 2004
C
Mar 29, 2004
C
Apr 01, 2004
Stewart Gordon
March 29, 2004
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.
March 29, 2004
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/
March 29, 2004
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.
March 29, 2004
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/
March 29, 2004
Inconsitency is a bug to me,

And this still works

int [] x;
x ~= 3;

but not this ?

char [] x;
x ~= '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 ~= ?
>>
>> 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.
>



-- 
D Newsgroup.
March 29, 2004
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 ~= 3;
>
> but not this ?
>
> char [] x;
> x ~= '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 ~= ?
>>>
>>> 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.
>>
>
>
>



-- 
D Newsgroup.
April 01, 2004
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.