digitalmars.D - string concatenation
- Andrei Alexandrescu (16/16) Nov 18 2009 TDPL boasts the code:
- Ellery Newcomer (4/25) Nov 18 2009 What are the current ideas on result type and why don't they dunk?
- Andrei Alexandrescu (5/31) Nov 18 2009 The result type would be the type of the left-hand side. This makes ~
- Ellery Newcomer (8/44) Nov 18 2009 I don't know what I ended up saying, but I meant
- Ellery Newcomer (2/13) Nov 18 2009 Crap, have I just inadvertently strengthened the argument against?
- Justin Johansson (6/54) Nov 18 2009 a = string( somewstring )
- Justin Johansson (2/17) Nov 18 2009 I meant for primitive types, of course.
- Ellery Newcomer (3/7) Nov 18 2009 From a syntactic perspective I disagree.
- Nick Sabalausky (3/48) Nov 19 2009 Isn't there "to!(char[])(whateverKindOfString)"?
- Justin Johansson (17/38) Nov 18 2009 Good; have third thoughts as well; the TDPL code is nothing to boast abo...
- div0 (16/59) Nov 19 2009 -----BEGIN PGP SIGNED MESSAGE-----
- Walter Bright (2/6) Nov 20 2009 Yeah, my thought too.
TDPL boasts the code: void main() { string a = "Hall\u00E5"; wstring b = ", "; dstring c = "V\u00E4rld"; auto d = b ~ c; // d has type wstring, same as b a ~= d ~ '!'; // concatenate string with character writeln(a); } We are having second thoughts about allowing b ~ c. It may be just a bit too clever. Also, figuring out the result type is not a slam dunk. The pro arguments are that strings are already supported by the compiler in iteration, literals, and concatenation of a char[] with a dchar. What say you? Andrei
Nov 18 2009
Andrei Alexandrescu wrote:TDPL boasts the code: void main() { string a = "Hall\u00E5"; wstring b = ", "; dstring c = "V\u00E4rld"; auto d = b ~ c; // d has type wstring, same as b a ~= d ~ '!'; // concatenate string with character writeln(a); } We are having second thoughts about allowing b ~ c. It may be just a bit too clever. Also, figuring out the result type is not a slam dunk. The pro arguments are that strings are already supported by the compiler in iteration, literals, and concatenation of a char[] with a dchar. What say you? AndreiWhat are the current ideas on result type and why don't they dunk? (personally, I like the idea of a syntax for converting from one unicode representation to another)
Nov 18 2009
Ellery Newcomer wrote:Andrei Alexandrescu wrote:The result type would be the type of the left-hand side. This makes ~ consistent of sorts with ~=.TDPL boasts the code: void main() { string a = "Hall\u00E5"; wstring b = ", "; dstring c = "V\u00E4rld"; auto d = b ~ c; // d has type wstring, same as b a ~= d ~ '!'; // concatenate string with character writeln(a); } We are having second thoughts about allowing b ~ c. It may be just a bit too clever. Also, figuring out the result type is not a slam dunk. The pro arguments are that strings are already supported by the compiler in iteration, literals, and concatenation of a char[] with a dchar. What say you? AndreiWhat are the current ideas on result type and why don't they dunk?(personally, I like the idea of a syntax for converting from one unicode representation to another)I don't think that's an option at the moment. Andrei
Nov 18 2009
Andrei Alexandrescu wrote:Ellery Newcomer wrote:That seems intuitive enough. Its what I would have guessed.Andrei Alexandrescu wrote:The result type would be the type of the left-hand side. This makes ~ consistent of sorts with ~=.TDPL boasts the code: void main() { string a = "Hall\u00E5"; wstring b = ", "; dstring c = "V\u00E4rld"; auto d = b ~ c; // d has type wstring, same as b a ~= d ~ '!'; // concatenate string with character writeln(a); } We are having second thoughts about allowing b ~ c. It may be just a bit too clever. Also, figuring out the result type is not a slam dunk. The pro arguments are that strings are already supported by the compiler in iteration, literals, and concatenation of a char[] with a dchar. What say you? AndreiWhat are the current ideas on result type and why don't they dunk?I don't know what I ended up saying, but I meant a = ""c ~ somewstring; beats a = std.utf.toString(somewstring); //no I'm not going to check if that's the right function am I still missing something?(personally, I like the idea of a syntax for converting from one unicode representation to another)I don't think that's an option at the moment. Andrei
Nov 18 2009
Ellery Newcomer wrote:I don't know what I ended up saying, but I meant a = ""c ~ somewstring; beats a = std.utf.toString(somewstring); //no I'm not going to check if that's the right function am I still missing something?Crap, have I just inadvertently strengthened the argument against?
Nov 18 2009
Ellery Newcomer wrote:Andrei Alexandrescu wrote:a = string( somewstring ) is much cleaner. This an example of a constructor function. Sadly, D does not support constructor functions (that I know of). Justin JohanssonEllery Newcomer wrote:That seems intuitive enough. Its what I would have guessed.Andrei Alexandrescu wrote:The result type would be the type of the left-hand side. This makes ~ consistent of sorts with ~=.TDPL boasts the code: void main() { string a = "Hall\u00E5"; wstring b = ", "; dstring c = "V\u00E4rld"; auto d = b ~ c; // d has type wstring, same as b a ~= d ~ '!'; // concatenate string with character writeln(a); } We are having second thoughts about allowing b ~ c. It may be just a bit too clever. Also, figuring out the result type is not a slam dunk. The pro arguments are that strings are already supported by the compiler in iteration, literals, and concatenation of a char[] with a dchar. What say you? AndreiWhat are the current ideas on result type and why don't they dunk?I don't know what I ended up saying, but I meant a = ""c ~ somewstring; beats a = std.utf.toString(somewstring); //no I'm not going to check if that's the right function am I still missing something?(personally, I like the idea of a syntax for converting from one unicode representation to another)I don't think that's an option at the moment. Andrei
Nov 18 2009
Justin Johansson wrote:Ellery Newcomer wrote:I meant for primitive types, of course.Andrei Alexandrescu wrote: a = std.utf.toString(somewstring); //no I'm not going to check if that's the right function am I still missing something?a = string( somewstring ) is much cleaner. This an example of a constructor function. Sadly, D does not support constructor functions (that I know of).
Nov 18 2009
Justin Johansson wrote:a = string( somewstring ) is much cleaner.From a syntactic perspective I disagree. Otherwise yup.
Nov 18 2009
"Ellery Newcomer" <ellery-newcomer utulsa.edu> wrote in message news:he2lm6$1h39$1 digitalmars.com...Andrei Alexandrescu wrote:Isn't there "to!(char[])(whateverKindOfString)"?Ellery Newcomer wrote:That seems intuitive enough. Its what I would have guessed.Andrei Alexandrescu wrote:The result type would be the type of the left-hand side. This makes ~ consistent of sorts with ~=.TDPL boasts the code: void main() { string a = "Hall\u00E5"; wstring b = ", "; dstring c = "V\u00E4rld"; auto d = b ~ c; // d has type wstring, same as b a ~= d ~ '!'; // concatenate string with character writeln(a); } We are having second thoughts about allowing b ~ c. It may be just a bit too clever. Also, figuring out the result type is not a slam dunk. The pro arguments are that strings are already supported by the compiler in iteration, literals, and concatenation of a char[] with a dchar. What say you? AndreiWhat are the current ideas on result type and why don't they dunk?I don't know what I ended up saying, but I meant a = ""c ~ somewstring; beats a = std.utf.toString(somewstring); //no I'm not going to check if that's the right function am I still missing something?(personally, I like the idea of a syntax for converting from one unicode representation to another)I don't think that's an option at the moment. Andrei
Nov 19 2009
Andrei Alexandrescu wrote:TDPL boasts the code: void main() { string a = "Hall\u00E5"; wstring b = ", "; dstring c = "V\u00E4rld"; auto d = b ~ c; // d has type wstring, same as b a ~= d ~ '!'; // concatenate string with character writeln(a); } We are having second thoughts about allowing b ~ c. It may be just a bit too clever. Also, figuring out the result type is not a slam dunk. The pro arguments are that strings are already supported by the compiler in iteration, literals, and concatenation of a char[] with a dchar. What say you? AndreiGood; have third thoughts as well; the TDPL code is nothing to boast about. Basically no thanks. con argument 1. Explicit conversion between string types is clearer to read in source code than auto-magic conversion. 2. Value types should be supported by constructor functions (and these can allow type conversion); hiding construction behind binary operators is evil. 3. People will end up writing concatenation with empty string to do their type conversion. This is the result of such evil. 4. Programs sprinkled with mixtures of strings, wstrings and dstrings are uncommon so it's trying to be a bit too clever to support the infrequent use cases. 5. It's less work for you and Walter to not allow such behind the scenes conversion. Justin Johansson
Nov 18 2009
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Justin Johansson wrote:Andrei Alexandrescu wrote:Also you'll be calling some behind the scenes runtime library function to do it anyway, in order to encode the dchars to multiple wchars. All seems a bit pointless really. - -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iD8DBQFLBaaYT9LetA9XoXwRAgxQAKCwdo12XokImcAX+A97VzmIywNuIgCdH1JG BTP5L+COxR704lknJMTkjRI= =Dljj -----END PGP SIGNATURE-----TDPL boasts the code: void main() { string a = "Hall\u00E5"; wstring b = ", "; dstring c = "V\u00E4rld"; auto d = b ~ c; // d has type wstring, same as b a ~= d ~ '!'; // concatenate string with character writeln(a); } We are having second thoughts about allowing b ~ c. It may be just a bit too clever. Also, figuring out the result type is not a slam dunk. The pro arguments are that strings are already supported by the compiler in iteration, literals, and concatenation of a char[] with a dchar. What say you? AndreiGood; have third thoughts as well; the TDPL code is nothing to boast about. Basically no thanks. con argument 1. Explicit conversion between string types is clearer to read in source code than auto-magic conversion. 2. Value types should be supported by constructor functions (and these can allow type conversion); hiding construction behind binary operators is evil. 3. People will end up writing concatenation with empty string to do their type conversion. This is the result of such evil. 4. Programs sprinkled with mixtures of strings, wstrings and dstrings are uncommon so it's trying to be a bit too clever to support the infrequent use cases. 5. It's less work for you and Walter to not allow such behind the scenes conversion.
Nov 19 2009
div0 wrote:Also you'll be calling some behind the scenes runtime library function to do it anyway, in order to encode the dchars to multiple wchars. All seems a bit pointless really.Yeah, my thought too.
Nov 20 2009