String Theory Questions

2014-09-13 Thread WhatMeWorry via Digitalmars-d-learn
The name string is aliased to immutable(char)[] Why was immutable chosen? Why not mutable. Or why not just make another alias called strung where it is aliased to mutable(char)[] Also, since strings are arrays and arrays are structs with a length and ptr field, I ran the following code for

Re: String Theory Questions

2014-09-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Sep 2014 17:09:56 + WhatMeWorry via Digitalmars-d-learn wrote: > I guess I was expecting them to be equivalent. I can understand > why both lengths are zero. But what is emptyStr.ptr doing with > the 42F080 value? I presume this is a address? If so, what does > this address c

Re: String Theory Questions

2014-09-13 Thread AsmMan via Digitalmars-d-learn
On Saturday, 13 September 2014 at 17:31:18 UTC, ketmar via Digitalmars-d-learn wrote: On Sat, 13 Sep 2014 17:09:56 + WhatMeWorry via Digitalmars-d-learn wrote: I guess I was expecting them to be equivalent. I can understand why both lengths are zero. But what is emptyStr.ptr doing wit

Re: String Theory Questions

2014-09-13 Thread ketmar via Digitalmars-d-learn
On Sat, 13 Sep 2014 22:41:38 + AsmMan via Digitalmars-d-learn wrote: > D string are actullay C-strings? in no way. only string *LITERALS* are zero-terminated. signature.asc Description: PGP signature

Re: String Theory Questions

2014-09-13 Thread David Nadlinger via Digitalmars-d-learn
On Saturday, 13 September 2014 at 22:41:39 UTC, AsmMan wrote: D string are actullay C-strings? No. But string *literals* are guaranteed to be 0-terminated for easier interoperability with C code. David

Re: String Theory Questions

2014-09-13 Thread WhatMeWorry via Digitalmars-d-learn
On Saturday, 13 September 2014 at 23:22:40 UTC, ketmar via Digitalmars-d-learn wrote: On Sat, 13 Sep 2014 22:41:38 + AsmMan via Digitalmars-d-learn wrote: D string are actullay C-strings? in no way. only string *LITERALS* are zero-terminated. Ok. So I wrote the following: char c = *(

Re: String Theory Questions

2014-09-13 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Sep 2014 00:34:54 + WhatMeWorry via Digitalmars-d-learn wrote: > So is one form (Empty strings versus null strings) considered > better than the other? Or does it depend on the context? one is better than another in the sense that blue is better than green (or vice versa). ;-) d

Re: String Theory Questions

2014-09-13 Thread Ali Çehreli via Digitalmars-d-learn
On 09/13/2014 05:34 PM, WhatMeWorry wrote: aren't all strings literals? Literals are values that are typed as is in source code: http://en.wikipedia.org/wiki/Literal_%28computer_programming%29 Ali

Re: String Theory Questions

2014-09-14 Thread Kagamin via Digitalmars-d-learn
On Sunday, 14 September 2014 at 00:34:56 UTC, WhatMeWorry wrote: So is one form (Empty strings versus null strings) considered better than the other? Or does it depend on the context? For all practical purposes they should be equivalent in D code. I suppose the distinction exists because some

Re: String Theory Questions

2014-09-14 Thread via Digitalmars-d-learn
On Sunday, 14 September 2014 at 09:07:26 UTC, Kagamin wrote: On Sunday, 14 September 2014 at 00:34:56 UTC, WhatMeWorry wrote: So is one form (Empty strings versus null strings) considered better than the other? Or does it depend on the context? For all practical purposes they should be equiva

Re: String Theory Questions

2014-09-14 Thread ketmar via Digitalmars-d-learn
On Sun, 14 Sep 2014 09:07:25 + Kagamin via Digitalmars-d-learn wrote: > Also for some reason boolean value of a string is derived from > ptr instead of length... meh. for the reason that all reference objects either "null" or "non-null". empty string is non-null, so... it's C leftover actual

Re: String Theory Questions

2014-09-14 Thread Mike Parker via Digitalmars-d-learn
On 9/14/2014 2:09 AM, WhatMeWorry wrote: The name string is aliased to immutable(char)[] Why was immutable chosen? Why not mutable. Or why not just make another alias called strung where it is aliased to mutable(char)[] If you want a mutable array of characters, just use char[]. --- This

Re: String Theory Questions

2014-09-14 Thread AsmMan via Digitalmars-d-learn
On Saturday, 13 September 2014 at 23:21:09 UTC, David Nadlinger wrote: On Saturday, 13 September 2014 at 22:41:39 UTC, AsmMan wrote: D string are actullay C-strings? No. But string *literals* are guaranteed to be 0-terminated for easier interoperability with C code. David ah makes sense.

Re: String Theory Questions

2014-09-14 Thread Kagamin via Digitalmars-d-learn
On Sunday, 14 September 2014 at 13:48:01 UTC, ketmar via Digitalmars-d-learn wrote: for the reason that all reference objects either "null" or "non-null". empty string is non-null, so... it's C leftover actually. there are alot such leftovers in D. For pointers it's logical, but it doesn't wo