Re: String to boolean inconsistency

2010-12-12 Thread spir
On Sun, 12 Dec 2010 04:00:36 +0100 Simen kjaeraas simen.kja...@gmail.com wrote: So likely, idup on an empty string returns an array with null ptr and 0 length, while is 'allocated' in the data segment, and thus given a ptr value. .dup .idup should not change a string's truth value. For

Re: String to boolean inconsistency

2010-12-12 Thread Simen kjaeraas
spir denis.s...@gmail.com wrote: On Sun, 12 Dec 2010 04:00:36 +0100 Simen kjaeraas simen.kja...@gmail.com wrote: So likely, idup on an empty string returns an array with null ptr and 0 length, while is 'allocated' in the data segment, and thus given a ptr value. .dup .idup should not

String to boolean inconsistency

2010-12-11 Thread Tomek Sowiński
string s = ; assert(s); // ok assert(s != null); // fails I guess that's a bug. But which one is right? -- Tomek

Re: String to boolean inconsistency

2010-12-11 Thread Ellery Newcomer
I forget, why are we supposed to use is instead of == with null? On 12/11/2010 08:18 PM, Tomek Sowiński wrote: string s = ; assert(s); // ok assert(s != null); // fails I guess that's a bug. But which one is right? -- Tomek

Re: String to boolean inconsistency

2010-12-11 Thread Andrej Mitrovic
The first one should fail since the string has length 0. If you use an .idup you would get the correct results: void main() { string s = .idup; assert(s); // fails assert(s != null); // ok } So I guess it's a bug. On 12/12/10, Tomek Sowiński j...@ask.me wrote: string s = ; assert(s); // ok

Re: String to boolean inconsistency

2010-12-11 Thread Andrej Mitrovic
Actually I'm having a hard time understanding this: void main() { string s = ; assert(s); // pass, but why? assert(s !is null); // pass } void main() { string s = .idup; assert(s); // fail assert(s !is null); // pass } On 12/12/10, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: The

Re: String to boolean inconsistency

2010-12-11 Thread Jonathan M Davis
On Saturday 11 December 2010 18:18:54 Tomek Sowiński wrote: string s = ; assert(s); // ok assert(s != null); // fails I guess that's a bug. But which one is right? A null array and an empty array are essentially the same thing as far as D is concerned. I believe that the only difference

Re: String to boolean inconsistency

2010-12-11 Thread Simen kjaeraas
Andrej Mitrovic andrej.mitrov...@gmail.com wrote: Actually I'm having a hard time understanding this: void main() { string s = ; assert(s); // pass, but why? assert(s !is null); // pass } void main() { string s = .idup; assert(s); // fail assert(s !is null); // pass } Try adding

Re: String to boolean inconsistency

2010-12-11 Thread Simen kjaeraas
Ellery Newcomer ellery-newco...@utulsa.edu wrote: I forget, why are we supposed to use is instead of == with null? '[] is null' compares ptr and length, while '[] == null' compares only the length. Weirdly though, '[] is null' is false for ptr == 0, length != 0. Not likely to happen much in

Re: String to boolean inconsistency

2010-12-11 Thread Simen kjaeraas
Simen kjaeraas simen.kja...@gmail.com wrote: Ellery Newcomer ellery-newco...@utulsa.edu wrote: I forget, why are we supposed to use is instead of == with null? '[] is null' compares ptr and length, while '[] == null' compares only the length. Weirdly though, '[] is null' is false for ptr ==

Re: String to boolean inconsistency

2010-12-11 Thread Simen kjaeraas
Jonathan M Davis jmdavisp...@gmx.com wrote: This behavior is intended. Arrays are actually something like this under the hood: struct array(T) { T* arr; size_t length; } Actually, that is: struct array(T) { size_t length; T* ptr; } To get the layout and names right. (

Re: String to boolean inconsistency

2010-12-11 Thread Jonathan M Davis
On Saturday 11 December 2010 19:00:55 Jonathan M Davis wrote: On Saturday 11 December 2010 18:18:54 Tomek Sowiński wrote: string s = ; assert(s); // ok assert(s != null); // fails I guess that's a bug. But which one is right? A null array and an empty array are essentially the

Re: String to boolean inconsistency

2010-12-11 Thread Jonathan M Davis
On Saturday 11 December 2010 19:08:33 Simen kjaeraas wrote: Jonathan M Davis jmdavisp...@gmx.com wrote: This behavior is intended. Arrays are actually something like this under the hood: struct array(T) { T* arr; size_t length; } Actually, that is: struct

Re: String to boolean inconsistency

2010-12-11 Thread Andrej Mitrovic
Coolio. I should pay a visit to druntime.. sometime. :) On 12/12/10, Jonathan M Davis jmdavisp...@gmx.com wrote: On Saturday 11 December 2010 19:00:55 Jonathan M Davis wrote: On Saturday 11 December 2010 18:18:54 Tomek Sowiński wrote: string s = ; assert(s); // ok assert(s != null); //

Re: String to boolean inconsistency

2010-12-11 Thread Jonathan M Davis
On Saturday 11 December 2010 19:16:29 Jonathan M Davis wrote: On Saturday 11 December 2010 19:08:33 Simen kjaeraas wrote: Jonathan M Davis jmdavisp...@gmx.com wrote: This behavior is intended. Arrays are actually something like this under the hood: struct array(T) {