September 14, 2014 Re: String Theory Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin Attachments: | On Sun, 14 Sep 2014 09:07:25 +0000 Kagamin via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> 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 actually. there are alot such leftovers in D. |
September 14, 2014 Re: String Theory Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to WhatMeWorry | 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 email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com |
September 14, 2014 Re: String Theory Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marc Schütz | 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. On Sunday, 14 September 2014 at 12:07:16 UTC, Marc Schütz wrote: > 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 equivalent in D code. I suppose the distinction exists because somebody claimed he can make sense of it. Some API may rely on distinction between null and empty string, like XML DOM, though I don't think such interface is very useful. >> >> Also for some reason boolean value of a string is derived from ptr instead of length... meh. > > Which makes sense given the distinction exists, IMO. Compare for example with Ruby, where empty strings and `0` integers also evaluate to true, but only `nil` and `false` evaluated to false. That's why I don't like most of dynamic languages... type system is a mess. I don't like even the fact one can do: x = "abc"; f(x) x = 10; g(x); and it work |
September 15, 2014 Re: String Theory Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | 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 work as good for slices: they're better thought of as either empty or non-empty.
|
Copyright © 1999-2021 by the D Language Foundation