digitalmars.D - Small idea: javascript-like string constants
- Lionello Lunesu (19/19) Dec 13 2005 Just a small idea, haven't really thought it fully through yet:
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/7) Dec 13 2005 D has length-prefixed strings instead, so I don't think that's correct ?
- Lionello Lunesu (14/20) Dec 13 2005 Well, ok, the array has a pointer to the actual value together with the
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (13/20) Dec 13 2005 Yes. One is a collection, the other is an item. :-)
- Lionello Lunesu (2/4) Dec 13 2005 THAT I didn't know :-) Thanks for pointing it out.
- Hasan Aljudy (6/26) Dec 13 2005 in D, you can use
-
Stewart Gordon
(13/16)
Dec 14 2005
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (7/10) Dec 14 2005 On my keyboard, it (`) is right next to the backspace key.
- Stewart Gordon (22/24) Dec 14 2005 It shouldn't be surprising that different languages use the same symbol
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/10) Dec 14 2005 [...]
- Lionello Lunesu (4/11) Dec 15 2005 It happens to be the same :-)
Just a small idea, haven't really thought it fully through yet: Since D has no zero-terminated strings, a character constant is basically the same as a string constant: 'a' and "a" are basically the same. This opens up the possibility of using ' and " similar to javascript (or python for that matter), being able to mix the two: 'blah "var"' would be the same as the current "blah \"var\"". While writing this the multi byte character constants come to mind. I do code similar to this in some C++ prog: long c = (long&)file_extension; switch (c) { case 'gepj':// jpeg case 'gpj'://jpg case 'agt'://tga // it's an image file } I'll still post this though, out of curiousity for the thoughts of the group. L.
Dec 13 2005
Lionello Lunesu wrote:Since D has no zero-terminated strings, a character constant is basically the same as a string constant: 'a' and "a" are basically the same.D has length-prefixed strings instead, so I don't think that's correct ? You can switch on strings in D, though... http://www.digitalmars.com/d/statement.html#switch --anders
Dec 13 2005
"Anders F Björklund" <afb algonet.se> wrote in message news:dnmcnb$rob$1 digitaldaemon.com...Lionello Lunesu wrote:Well, ok, the array has a pointer to the actual value together with the length: char[1] b = "a"; //points to an 'a' in memory, paired with length 1 Whereas in C "a" and 'a' would have nothing in common: the former being a pointer to {97,0} and the latter being just the value 97. In D it's no longer to think of "a" as 'a pointer to a string', eventhough arrays contain a pointer to the string. I think of "a" as being a collection of characters, this one having only 'a'. Is a collection with only 'a' different from just 'a'? How is a char[1] different from a char?Since D has no zero-terminated strings, a character constant is basically the same as a string constant: 'a' and "a" are basically the same.D has length-prefixed strings instead, so I don't think that's correct ?You can switch on strings in D, though... http://www.digitalmars.com/d/statement.html#switchWhich makes the strange (and not portable) switch construct in my original post obsolete! L.
Dec 13 2005
Lionello Lunesu wrote:Whereas in C "a" and 'a' would have nothing in common: the former being a pointer to {97,0} and the latter being just the value 97.Pretty much in common, yes ? i.e. char[0] == charIn D it's no longer to think of "a" as 'a pointer to a string', eventhough arrays contain a pointer to the string. I think of "a" as being a collection of characters, this one having only 'a'. Is a collection with only 'a' different from just 'a'?Yes. One is a collection, the other is an item. :-)How is a char[1] different from a char?It isn't. But null-terminated arrays and length-prefixed arrays are also very similar. Don't get me wrong, I also like D's "code unit" arrays better than C's "character" arrays... But they are not really *that* different from eachother ? And you can use raw D strings for things with double-quotes: `blah "var"` The only downside being that in shell scripts and other languages, the backticks means to escape to a sub-process... --anders
Dec 13 2005
And you can use raw D strings for things with double-quotes: `blah "var"`THAT I didn't know :-) Thanks for pointing it out. L.
Dec 13 2005
Lionello Lunesu wrote:Just a small idea, haven't really thought it fully through yet: Since D has no zero-terminated strings, a character constant is basically the same as a string constant: 'a' and "a" are basically the same.Well it's not, as been shown in another post.This opens up the possibility of using ' and " similar to javascript (or python for that matter), being able to mix the two: 'blah "var"' would be the same as the current "blah \"var\"".in D, you can use `blah "quote" etc` (that is not the single quote ' it's the thing in the ~ button)While writing this the multi byte character constants come to mind. I do code similar to this in some C++ prog: long c = (long&)file_extension; switch (c) { case 'gepj':// jpeg case 'gpj'://jpg case 'agt'://tga // it's an image file }You can do switch on strings in D
Dec 13 2005
Hasan Aljudy wrote: <snip>in D, you can use `blah "quote" etc` (that is not the single quote ' it's the thing in the ~ button)<snip> Have you checked that Lionello's keyboard is exactly the same as yours? Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Dec 14 2005
Stewart Gordon wrote:On my keyboard, it (`) is right next to the backspace key. And I don't have a ~ key either... Just us non-US weirdos. :-) --anders PS. Backticks are still dumb to use for the raw strings, regardless... (since they're used elsewhere to run commands. But it's too late)(that is not the single quote ' it's the thing in the ~ button)Have you checked that Lionello's keyboard is exactly the same as yours?
Dec 14 2005
Anders F Björklund wrote: <snip>Backticks are still dumb to use for the raw strings, regardless... (since they're used elsewhere to run commands. But it's too late)It shouldn't be surprising that different languages use the same symbol to mean different things. Just to name a few: ^: bitwise XOR in C(++), D, etc. Exponentiation in BASIC, Excel, etc. Beginning of line or 'not' in regexp. Statement separator in 4DOS. $: string variable marker in BASIC. Scalar variable marker in Perl and Unix shell scripts. End of array in D. Mingle operator in INTERCAL. -: subtraction in most languages. Just another character to use in variable names in COBOL. , make and Maple. Double precision (?) variable marker in some BASICs. {}: block statement in C(++), D, etc. Comment in Pascal. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:- C++ a->--- UB P+ L E W++ N+++ o K- w++ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Dec 14 2005
Stewart Gordon wrote:[...] Nope, just that this particular one has me confused every single time. Then again it's used once in a blue moon so it's not really a problem. --andersBackticks are still dumb to use for the raw strings, regardless... (since they're used elsewhere to run commands. But it's too late)It shouldn't be surprising that different languages use the same symbol to mean different things. Just to name a few:
Dec 14 2005
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:dnp4ft$tiu$1 digitaldaemon.com...Hasan Aljudy wrote: <snip>It happens to be the same :-) L.in D, you can use `blah "quote" etc` (that is not the single quote ' it's the thing in the ~ button)<snip> Have you checked that Lionello's keyboard is exactly the same as yours?
Dec 15 2005