D - Int to string
- Overlord (13/13) Aug 16 2001 In D strings can be copied, compared, concatenated, and appended like th...
- Walter (4/17) Aug 17 2001 Automatic coercion of ints to strings works well in typeless languages l...
- Tim Sweeney (17/30) Aug 17 2001 Using "+" for string concatenation always leads to confusing ambiguities...
- Walter (21/59) Aug 17 2001 I've been thinking that string concatenation should use a different oper...
- kaffiene (8/74) Aug 18 2001 In practice (Java) + for string concatenation works fine - but there is ...
- Overlord (9/75) Aug 23 2001 i think the poor old '+' is a goo way to do it because it is simple, not
- Eric Gerlach (10/16) Aug 25 2001 PHP uses '.'.
- timeless (2/5) Feb 17 2002 perl uses '.', i don't know who used it first.
- Pavel Minayev (4/9) Feb 17 2002 operator
- DrWhat? (30/42) Feb 20 2002 Good point - it is always an annoyance explaining that '+' can mean
- Pavel Minayev (6/10) Feb 20 2002 Actually, it reminds me of math "not equal" sign more...
- d (7/17) Feb 21 2002 Yes apparently it was realized that overloading the "+" operator for str...
In D strings can be copied, compared, concatenated, and appended like this. str1 = str2; if (str1 < str3) ... func(str3 + str4); str4 += str1; But if you want to add a integer into this, does(or will) D support it like this(or in some simmilar way)? int i=10; char[] str = "abc"; str1 = i; // str1="10" if (str == i) ... func(str + i); // abc10 str += i; //same as above
Aug 16 2001
Overlord wrote in message <9lgrsh$2e8c$1 digitaldaemon.com>...In D strings can be copied, compared, concatenated, and appended like this. str1 = str2; if (str1 < str3) ... func(str3 + str4); str4 += str1; But if you want to add a integer into this, does(or will) D support it like this(or in some simmilar way)? int i=10; char[] str = "abc"; str1 = i; // str1="10" if (str == i) ... func(str + i); // abc10 str += i; //same as aboveAutomatic coercion of ints to strings works well in typeless languages like basic and javascript, but such conversions can have unexpected results, so it's probably best to leave that to an explicit conversion.
Aug 17 2001
Using "+" for string concatenation always leads to confusing ambiguities. In a language without overloading or templates, this can still work, but requires the user to sometimes perform mental gymnastics figuring out "why am I getting weird results using + in this context?" However, if templates or overloading are present, then you run into even worse ambiguity problems. To avoid ambiguity, you really need to have separate syntax for: adding (i.e. integers). concatenating arrays (strings just like any other case). prepending one t to a t[]. appending one t to a t[]. Note that this is provable rather than speculation. :-) -Tim "Overlord" <peewee telia.com> wrote in message news:9lgrsh$2e8c$1 digitaldaemon.com...In D strings can be copied, compared, concatenated, and appended likethis.str1 = str2; if (str1 < str3) ... func(str3 + str4); str4 += str1; But if you want to add a integer into this, does(or will) D support itlikethis(or in some simmilar way)? int i=10; char[] str = "abc"; str1 = i; // str1="10" if (str == i) ... func(str + i); // abc10 str += i; //same as above
Aug 17 2001
I've been thinking that string concatenation should use a different operator than the poor old '+'. It should have the same precedence as '+'. Any suggestions? Some candidates: $ ~ ! Let's see what they look like: foo = bar + "hello" + bar + "\n"; foo = bar ~ "hello" ~ bar ~ "\n"; foo = bar ! "hello" ! bar ! "\n"; foo = bar "hello" bar "\n"; I kinda like the !. What do other languages use? Multi-character tokens are also possible, such as !+!, <+>, |+|, -+-, etc. foo = bar !+! "hello" !+! bar !+! "\n"; foo = bar -+- "hello" -+- bar -+- "\n"; Hmm. Doesn't look so good <g>. Tim Sweeney wrote in message <9lkgci$2og9$1 digitaldaemon.com>...Using "+" for string concatenation always leads to confusing ambiguities. In a language without overloading or templates, this can still work, but requires the user to sometimes perform mental gymnastics figuring out "why am I getting weird results using + in this context?" However, if templates or overloading are present, then you run into even worse ambiguity problems. To avoid ambiguity, you really need to have separate syntax for: adding (i.e. integers). concatenating arrays (strings just like any other case). prepending one t to a t[]. appending one t to a t[]. Note that this is provable rather than speculation. :-) -Tim "Overlord" <peewee telia.com> wrote in message news:9lgrsh$2e8c$1 digitaldaemon.com...In D strings can be copied, compared, concatenated, and appended likethis.str1 = str2; if (str1 < str3) ... func(str3 + str4); str4 += str1; But if you want to add a integer into this, does(or will) D support itlikethis(or in some simmilar way)? int i=10; char[] str = "abc"; str1 = i; // str1="10" if (str == i) ... func(str + i); // abc10 str += i; //same as above
Aug 17 2001
In practice (Java) + for string concatenation works fine - but there is no operator overloading in Java, so I guess there's less possibilities for it to get confused with. Peter. "Walter" <walter digitalmars.com> wrote in message news:9lkk0f$2qdq$1 digitaldaemon.com...I've been thinking that string concatenation should use a differentoperatorthan the poor old '+'. It should have the same precedence as '+'. Any suggestions? Some candidates: $ ~ ! Let's see what they look like: foo = bar + "hello" + bar + "\n"; foo = bar ~ "hello" ~ bar ~ "\n"; foo = bar ! "hello" ! bar ! "\n"; foo = bar "hello" bar "\n"; I kinda like the !. What do other languages use? Multi-character tokens are also possible, such as !+!, <+>, |+|, -+-, etc. foo = bar !+! "hello" !+! bar !+! "\n"; foo = bar -+- "hello" -+- bar -+- "\n"; Hmm. Doesn't look so good <g>. Tim Sweeney wrote in message <9lkgci$2og9$1 digitaldaemon.com>..."whyUsing "+" for string concatenation always leads to confusing ambiguities. In a language without overloading or templates, this can still work, but requires the user to sometimes perform mental gymnastics figuring outam I getting weird results using + in this context?" However, if templates or overloading are present, then you run into even worse ambiguity problems. To avoid ambiguity, you really need to have separate syntax for: adding (i.e. integers). concatenating arrays (strings just like any other case). prepending one t to a t[]. appending one t to a t[]. Note that this is provable rather than speculation. :-) -Tim "Overlord" <peewee telia.com> wrote in message news:9lgrsh$2e8c$1 digitaldaemon.com...In D strings can be copied, compared, concatenated, and appended likethis.str1 = str2; if (str1 < str3) ... func(str3 + str4); str4 += str1; But if you want to add a integer into this, does(or will) D support itlikethis(or in some simmilar way)? int i=10; char[] str = "abc"; str1 = i; // str1="10" if (str == i) ... func(str + i); // abc10 str += i; file://same as above
Aug 18 2001
i think the poor old '+' is a goo way to do it because it is simple, not only can it be used by strings but arrays in general can use it. But if you really want another operator you can use << and >> like in cout/cin str=str1 << str2; // adds str2 after str1 Walter <walter digitalmars.com> skrev i diskussionsgruppsmeddelandet:9lkk0f$2qdq$1 digitaldaemon.com...I've been thinking that string concatenation should use a differentoperatorthan the poor old '+'. It should have the same precedence as '+'. Any suggestions? Some candidates: $ ~ ! Let's see what they look like: foo = bar + "hello" + bar + "\n"; foo = bar ~ "hello" ~ bar ~ "\n"; foo = bar ! "hello" ! bar ! "\n"; foo = bar "hello" bar "\n"; I kinda like the !. What do other languages use? Multi-character tokens are also possible, such as !+!, <+>, |+|, -+-, etc. foo = bar !+! "hello" !+! bar !+! "\n"; foo = bar -+- "hello" -+- bar -+- "\n"; Hmm. Doesn't look so good <g>. Tim Sweeney wrote in message <9lkgci$2og9$1 digitaldaemon.com>..."whyUsing "+" for string concatenation always leads to confusing ambiguities. In a language without overloading or templates, this can still work, but requires the user to sometimes perform mental gymnastics figuring outam I getting weird results using + in this context?" However, if templates or overloading are present, then you run into even worse ambiguity problems. To avoid ambiguity, you really need to have separate syntax for: adding (i.e. integers). concatenating arrays (strings just like any other case). prepending one t to a t[]. appending one t to a t[]. Note that this is provable rather than speculation. :-) -Tim "Overlord" <peewee telia.com> wrote in message news:9lgrsh$2e8c$1 digitaldaemon.com...In D strings can be copied, compared, concatenated, and appended likethis.str1 = str2; if (str1 < str3) ... func(str3 + str4); str4 += str1; But if you want to add a integer into this, does(or will) D support itlikethis(or in some simmilar way)? int i=10; char[] str = "abc"; str1 = i; // str1="10" if (str == i) ... func(str + i); // abc10 str += i; file://same as above
Aug 23 2001
I've been thinking that string concatenation should use a different operator than the poor old '+'. It should have the same precedence as '+'. Any suggestions? What do other languages use?PHP uses '.'. ex: $hello = "hello"; $world = "world"; print ($hello . " " . $world . "\n"); It's really a nice operator for it. Unfortunately, this creates a parsing nightmare when the language's object reference operator is '.'... I'm a bit partial towards '~' for string concat. Eric
Aug 25 2001
Walter wrote:I've been thinking that string concatenation should use a different operator than the poor old '+'. It should have the same precedence as '+'. Any suggestions?perl uses '.', i don't know who used it first.
Feb 17 2002
"timeless" <timeless mac.com> wrote in message news:3C702F4D.662B3958 mac.com...Walter wrote:operatorI've been thinking that string concatenation should use a differentD uses ~ already.than the poor old '+'. It should have the same precedence as '+'. Any suggestions?perl uses '.', i don't know who used it first.
Feb 17 2002
Pavel Minayev wrote:"timeless" <timeless mac.com> wrote in message news:3C702F4D.662B3958 mac.com...Good point - it is always an annoyance explaining that '+' can mean either concatenation or addition in my Java labs, one of the things Java got wrong in my opinion and one of the things beginner can easily get stung by take for example these System.out.println( i+1+": "+args[n] ); // output "<i+1>: <args[n]>" System.out.println( ": "+i+1+args[n]) ); // output ": <i>1<args[n]>"Walter wrote:I've been thinking that string concatenation should use a different operator than the poor old '+'.Good, but there has been some complaints about the tilda not existing on some keyboards (at a quick look it is in a different place on each of the FOUR keyboards in front of me currently - and none existant on the fifth, this is not a good situation for touch typists). Not to mention it is difficult to guess (not really a problem - just good practice) and beginners will confuse it with the inversion operator. My suggestions would be symbol ( memory aid ) ( a for add / array ) $ [ well - basic programmers will like it :-) ] ++ ( plus plus end ) |+ ( add to end ) [ ++ may conflict with pre and post increment operators, making parsing difficult - though I presonally would dispose of pre & post operators as they make code difficult to read when overused, I expect that you will want them kept as this coincides with C syntax] C 2001/2/20 "... one of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs." --Robert FirthD uses ~ already.It should have the same precedence as '+'. Any suggestions?perl uses '.', i don't know who used it first.
Feb 20 2002
"DrWhat?" <DrWhat nospam.madscientist.co.uk> wrote in message news:a50fng$1216$1 digitaldaemon.com...symbol ( memory aid )Actually, it reminds me of math "not equal" sign more...( a for add / array )Since it usually means "at", I guess it's not the best idea...$ [ well - basic programmers will like it :-) ]UnrealScripters as well. I have nothing against it, although I like tilde a bit better. It reminds me of a "rope": a~b. Sorta mnemonic =)
Feb 20 2002
Yes apparently it was realized that overloading the "+" operator for strings was confusing. It's even more confusing for virtually every other overloading function. That is why operator overloading is a very bad thing and should be avoided. I laugh. Pavel Minayev <evilone omen.ru> wrote in message news:a4q2kp$1i0s$1 digitaldaemon.com..."timeless" <timeless mac.com> wrote in message news:3C702F4D.662B3958 mac.com...Walter wrote:operatorI've been thinking that string concatenation should use a differentD uses ~ already.than the poor old '+'. It should have the same precedence as '+'. Any suggestions?perl uses '.', i don't know who used it first.
Feb 21 2002