digitalmars.D.bugs - Concatenating with a string array
- Nick (12/12) Feb 10 2006 This should work, shouldn't it?
- Yves Jacoby (3/19) Feb 10 2006 Yves
- Jarrett Billingsley (9/11) Feb 10 2006 They should both work, as according to the Array spec,
- Thomas Kuehne (11/23) Feb 12 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Walter Bright (9/22) Feb 15 2006 The a~="hello" should work because ~= can do two different things:
- Derek Parnell (13/38) Feb 15 2006 I would like to register my concern with this position.
- Chris Sauls (4/35) Feb 15 2006 Maybe the order of (1) & (2) should be inverted for the '~' operator and...
- Thomas Kuehne (11/35) Feb 23 2006 -----BEGIN PGP SIGNED MESSAGE-----
This should work, shouldn't it? void main() { char[][] a; a ~= "hello"; // Works a = a ~ "world"; // Error } tst.d(5): incompatible types for ((a) ~ ("world")): 'char[][]' and 'char[5]' tst.d(5): Can only concatenate arrays, not (char[][] ~ char[5]) tst.d(5): cannot implicitly convert expression ((a) ~ "world") of type int to char[][] Nick
Feb 10 2006
On Fri, 10 Feb 2006 12:01:56 +0000, Nick wrote:This should work, shouldn't it? void main() { char[][] a; a ~= "hello"; // Works a = a ~ "world"; // Error } tst.d(5): incompatible types for ((a) ~ ("world")): 'char[][]' and 'char[5]' tst.d(5): Can only concatenate arrays, not (char[][] ~ char[5]) tst.d(5): cannot implicitly convert expression ((a) ~ "world") of type int to char[][] NickWhy should the first one work ? I mean:a ~= "hello"; // WorksYves
Feb 10 2006
"Yves Jacoby" <kloune gmail.com> wrote in message news:pan.2006.02.10.12.12.50.539634 gmail.com...Why should the first one work ? I mean:They should both work, as according to the Array spec, A static array T[dim] can be implicitly converted to one of the following: - T* - T[] "hello" is of type char[5]. Thus, it is implicitly convertible to char[]. Likewise, "world" is also of char[5], and should also be implicitly converted.a ~= "hello"; // Works
Feb 10 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Nick schrieb am 2006-02-10:This should work, shouldn't it? void main() { char[][] a; a ~= "hello"; // Works a = a ~ "world"; // Error } tst.d(5): incompatible types for ((a) ~ ("world")): 'char[][]' and 'char[5]' tst.d(5): Can only concatenate arrays, not (char[][] ~ char[5]) tst.d(5): cannot implicitly convert expression ((a) ~ "world") of type int to char[][] NickAdded to DStess as http://dstress.kuehne.cn/run/o/opCat_20.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD7vNI3w+/yD4P9tIRAhcuAJoCb5RZOeKX3ILZvTKyq5LUYDUGtACglZjb 8xfNuPKeGcoINBIWVjj10fg= =mmV/ -----END PGP SIGNATURE-----
Feb 12 2006
"Nick" <Nick_member pathlink.com> wrote in message news:dshvbk$qop$1 digitaldaemon.com...This should work, shouldn't it? void main() { char[][] a; a ~= "hello"; // Works a = a ~ "world"; // Error } tst.d(5): incompatible types for ((a) ~ ("world")): 'char[][]' and 'char[5]' tst.d(5): Can only concatenate arrays, not (char[][] ~ char[5]) tst.d(5): cannot implicitly convert expression ((a) ~ "world") of type int to char[][]The a~="hello" should work because ~= can do two different things: 1) append an element to an array 2) append an array of elements to an array The a~="hello" is an example of (1). The a=a~"hello" should not work, because ~ only does (2). I'm a little concerned that modifying it to do (1) as well will introduce unanticipated problems.
Feb 15 2006
On Thu, 16 Feb 2006 04:11:13 +1100, Walter Bright <newshound digitalmars.com> wrote:"Nick" <Nick_member pathlink.com> wrote in message news:dshvbk$qop$1 digitaldaemon.com...I would like to register my concern with this position. However, the underlying issue seems to be the attempt to concatenate fixed length arrays with variable length arrays, and that string literals are sometimes only seens as fixed length arrays. When assigning to a variable length arrays, the compiler should recognise that fixed length arrays are proper fellows to be concatenated. In fact, concatenation always implies variable length arrays so the compiler should just do it that way. -- Derek Parnell Melbourne, AustraliaThis should work, shouldn't it? void main() { char[][] a; a ~= "hello"; // Works a = a ~ "world"; // Error } tst.d(5): incompatible types for ((a) ~ ("world")): 'char[][]' and 'char[5]' tst.d(5): Can only concatenate arrays, not (char[][] ~ char[5]) tst.d(5): cannot implicitly convert expression ((a) ~ "world") of type int to char[][]The a~="hello" should work because ~= can do two different things: 1) append an element to an array 2) append an array of elements to an array The a~="hello" is an example of (1). The a=a~"hello" should not work, because ~ only does (2). I'm a little concerned that modifying it to do (1) as well will introduce unanticipated problems.
Feb 15 2006
Walter Bright wrote:"Nick" <Nick_member pathlink.com> wrote in message news:dshvbk$qop$1 digitaldaemon.com...Maybe the order of (1) & (2) should be inverted for the '~' operator and left as-is for the '~=' operator? -- Chris Nicholson-SaulsThis should work, shouldn't it? void main() { char[][] a; a ~= "hello"; // Works a = a ~ "world"; // Error } tst.d(5): incompatible types for ((a) ~ ("world")): 'char[][]' and 'char[5]' tst.d(5): Can only concatenate arrays, not (char[][] ~ char[5]) tst.d(5): cannot implicitly convert expression ((a) ~ "world") of type int to char[][]The a~="hello" should work because ~= can do two different things: 1) append an element to an array 2) append an array of elements to an array The a~="hello" is an example of (1). The a=a~"hello" should not work, because ~ only does (2). I'm a little concerned that modifying it to do (1) as well will introduce unanticipated problems.
Feb 15 2006
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Walter Bright schrieb am 2006-02-15:"Nick" <Nick_member pathlink.com> wrote in message news:dshvbk$qop$1 digitaldaemon.com...The documentation of "array ~= x" seems a bit vague. (http://digitalmars.com/d/arrays.html) only documents (2) not (1). Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFD/rqU3w+/yD4P9tIRAvm0AJ9ANAnttjBLDgrDeEo4PxjtdgMNYQCfcmk8 oRYsDKYliGegsqLZwx2g9RY= =tCN3 -----END PGP SIGNATURE-----This should work, shouldn't it? void main() { char[][] a; a ~= "hello"; // Works a = a ~ "world"; // Error } tst.d(5): incompatible types for ((a) ~ ("world")): 'char[][]' and 'char[5]' tst.d(5): Can only concatenate arrays, not (char[][] ~ char[5]) tst.d(5): cannot implicitly convert expression ((a) ~ "world") of type int to char[][]The a~="hello" should work because ~= can do two different things: 1) append an element to an array 2) append an array of elements to an array The a~="hello" is an example of (1). The a=a~"hello" should not work, because ~ only does (2). I'm a little concerned that modifying it to do (1) as well will introduce unanticipated problems.
Feb 23 2006