Re: arrays: if(null == [ ])

2012-05-23 Thread Marco Leise
Am Wed, 16 May 2012 09:18:38 -0400 schrieb "Steven Schveighoffer" : > Regardless, we should fix if(!arr) to mean if(!arr.length). > > -Steve I'm still using 2.057 (GDC). My mental model of D tells me: A reference type's pointer is implicitly converted to bool, when used inside an if-expression.

Re: arrays: if(null == [ ])

2012-05-17 Thread Regan Heath
On Thu, 17 May 2012 00:08:49 +0100, Jonathan M Davis wrote: On Wednesday, May 16, 2012 09:18:38 Steven Schveighoffer wrote: but I still think we should discourage using null as a sentinel, it leads to confusing code. If null were actually properly differentiated from empty, then this wou

Re: arrays: if(null == [ ])

2012-05-17 Thread deadalnix
Le 16/05/2012 23:15, Steven Schveighoffer a écrit : On Wed, 16 May 2012 17:11:58 -0400, deadalnix wrote: Le 16/05/2012 15:12, Steven Schveighoffer a écrit : On Tue, 15 May 2012 04:42:10 -0400, deadalnix wrote: Le 14/05/2012 21:53, Steven Schveighoffer a écrit : On Mon, 14 May 2012 15:30:2

Re: arrays: if(null == [ ])

2012-05-16 Thread Jonathan M Davis
On Wednesday, May 16, 2012 09:18:38 Steven Schveighoffer wrote: > but I still think we should discourage using null as a > sentinel, it leads to confusing code. If null were actually properly differentiated from empty, then this wouldn't be a problem, but it's not. It _should_ be possible to trea

Re: arrays: if(null == [ ])

2012-05-16 Thread Steven Schveighoffer
On Wed, 16 May 2012 17:11:58 -0400, deadalnix wrote: Le 16/05/2012 15:12, Steven Schveighoffer a écrit : On Tue, 15 May 2012 04:42:10 -0400, deadalnix wrote: Le 14/05/2012 21:53, Steven Schveighoffer a écrit : On Mon, 14 May 2012 15:30:25 -0400, deadalnix wrote: Le 14/05/2012 16:37, S

Re: arrays: if(null == [ ])

2012-05-16 Thread deadalnix
Le 16/05/2012 15:12, Steven Schveighoffer a écrit : On Tue, 15 May 2012 04:42:10 -0400, deadalnix wrote: Le 14/05/2012 21:53, Steven Schveighoffer a écrit : On Mon, 14 May 2012 15:30:25 -0400, deadalnix wrote: Le 14/05/2012 16:37, Steven Schveighoffer a écrit : Note that [] is a request t

Re: arrays: if(null == [ ])

2012-05-16 Thread Timon Gehr
On 05/16/2012 04:23 PM, bearophile wrote: Is this request in Bugzilla? http://d.puremagic.com/issues/show_bug.cgi?id=4733 http://d.puremagic.com/issues/show_bug.cgi?id=7539 The first report happens to be yours =).

Re: arrays: if(null == [ ])

2012-05-16 Thread Tobias Pankrath
On Wednesday, 16 May 2012 at 14:26:49 UTC, Alex Rønne Petersen wrote: On 16-05-2012 16:23, bearophile wrote: Steven Schveighoffer: Regardless, we should fix if(!arr) to mean if(!arr.length). This seems a nice idea (and Python programmers will be thankful, because they are used to empty coll

Re: arrays: if(null == [ ])

2012-05-16 Thread Alex Rønne Petersen
On 16-05-2012 16:23, bearophile wrote: Steven Schveighoffer: Regardless, we should fix if(!arr) to mean if(!arr.length). This seems a nice idea (and Python programmers will be thankful, because they are used to empty collections/strings to be false). Is this request in Bugzilla? Are people op

Re: arrays: if(null == [ ])

2012-05-16 Thread bearophile
Steven Schveighoffer: Regardless, we should fix if(!arr) to mean if(!arr.length). This seems a nice idea (and Python programmers will be thankful, because they are used to empty collections/strings to be false). Is this request in Bugzilla? Are people opposed to this little D breaking chang

Re: arrays: if(null == [ ])

2012-05-16 Thread Steven Schveighoffer
On Mon, 14 May 2012 18:07:24 -0400, Timon Gehr wrote: On 05/14/2012 01:51 PM, deadalnix wrote: Le 14/05/2012 12:49, Gor Gyolchanyan a écrit : So, null arrays and empty arrays are always the same, except for an empty string, which is a valid non-nill array of characters with length 0, right?

Re: arrays: if(null == [ ])

2012-05-16 Thread Steven Schveighoffer
On Tue, 15 May 2012 04:42:10 -0400, deadalnix wrote: Le 14/05/2012 21:53, Steven Schveighoffer a écrit : On Mon, 14 May 2012 15:30:25 -0400, deadalnix wrote: Le 14/05/2012 16:37, Steven Schveighoffer a écrit : Note that [] is a request to the runtime to build an empty array. The runtime

Re: arrays: if(null == [ ])

2012-05-15 Thread Jonathan M Davis
On Wednesday, May 16, 2012 00:48:44 Gor Gyolchanyan wrote: > No, no and no. toUTFz could be called at compile-time. Absolutely no extra > run-time allocations, absolutely no run-time overhead. So, you're going to create a bunch of enums just to pass string literals to C functions? Stuff like this

Re: arrays: if(null == [ ])

2012-05-15 Thread Andrej Mitrovic
On 5/15/12, Gor Gyolchanyan wrote: > No, no and no. toUTFz could be called at compile-time. Absolutely no extra > run-time allocations, absolutely no run-time overhead. How about programmer-time overhead? Are *you* volunteering to edit all the codebases out there that rely on having 0-terminated

Re: arrays: if(null == [ ])

2012-05-15 Thread deadalnix
Le 15/05/2012 15:29, Alex Rønne Petersen a écrit : On 15-05-2012 15:22, Gor Gyolchanyan wrote: On Tue, May 15, 2012 at 4:00 PM, Alex Rønne Petersen mailto:xtzgzo...@gmail.com>> wrote: Yes, because using a Phobos function in druntime is perfectly possible! Totally! -- - Alex Isn't it obvious

Re: arrays: if(null == [ ])

2012-05-15 Thread Gor Gyolchanyan
No, no and no. toUTFz could be called at compile-time. Absolutely no extra run-time allocations, absolutely no run-time overhead. On Tue, May 15, 2012 at 11:05 PM, Jonathan M Davis wrote: > On Tuesday, May 15, 2012 17:35:58 Gor Gyolchanyan wrote: > > Even if it's wrong to move writef to druntime,

Re: arrays: if(null == [ ])

2012-05-15 Thread Jonathan M Davis
On Tuesday, May 15, 2012 17:35:58 Gor Gyolchanyan wrote: > Even if it's wrong to move writef to druntime, the toUTFz is still a very > small word to write. Using toStringz or toUTFz instead of having string literals be zero-terminated would force allocating extra strings (string literals are in a

Re: arrays: if(null == [ ])

2012-05-15 Thread Timon Gehr
On 05/15/2012 12:09 PM, Gor Gyolchanyan wrote: There's not reason to use printf! This is ridiculous! We haev a type-safe writef, which does exactly that and does it better. Besides, wrapping the literal into a toUTFz is not too difficult!

Re: arrays: if(null == [ ])

2012-05-15 Thread Gor Gyolchanyan
UTF manipulation functions are fundamental enough, because all of D's strings are UTF-something. I think std.utf deserves to be in druntime. On Tue, May 15, 2012 at 6:05 PM, Alex Rønne Petersen wrote: > On 15-05-2012 15:35, Gor Gyolchanyan wrote: > >> Even if it's wrong to move writef to druntime

Re: arrays: if(null == [ ])

2012-05-15 Thread Alex Rønne Petersen
On 15-05-2012 15:35, Gor Gyolchanyan wrote: Even if it's wrong to move writef to druntime, the toUTFz is still a very small word to write. On Tue, May 15, 2012 at 5:29 PM, Alex Rønne Petersen mailto:xtzgzo...@gmail.com>> wrote: On 15-05-2012 15:22, Gor Gyolchanyan wrote: On Tue, Ma

Re: arrays: if(null == [ ])

2012-05-15 Thread Gor Gyolchanyan
Even if it's wrong to move writef to druntime, the toUTFz is still a very small word to write. On Tue, May 15, 2012 at 5:29 PM, Alex Rønne Petersen wrote: > On 15-05-2012 15:22, Gor Gyolchanyan wrote: > >> On Tue, May 15, 2012 at 4:00 PM, Alex Rønne Petersen >> mailto:xtzgzo...@gmail.com>> wrote:

Re: arrays: if(null == [ ])

2012-05-15 Thread Alex Rønne Petersen
On 15-05-2012 15:22, Gor Gyolchanyan wrote: On Tue, May 15, 2012 at 4:00 PM, Alex Rønne Petersen mailto:xtzgzo...@gmail.com>> wrote: Yes, because using a Phobos function in druntime is perfectly possible! Totally! -- - Alex Isn't it obvious what needs to be done? Come on, it

Re: arrays: if(null == [ ])

2012-05-15 Thread Gor Gyolchanyan
On Tue, May 15, 2012 at 4:00 PM, Alex Rønne Petersen wrote: > > Yes, because using a Phobos function in druntime is perfectly possible! > Totally! > -- > - Alex > Isn't it obvious what needs to be done? Come on, it's no too hard to see... -- Bye, Gor Gyolchanyan.

Re: arrays: if(null == [ ])

2012-05-15 Thread Alex Rønne Petersen
On 15-05-2012 12:09, Gor Gyolchanyan wrote: There's not reason to use printf! This is ridiculous! We haev a type-safe writef, which does exactly that and does it better. Besides, wrapping the literal into a toUTFz is not too difficult! On Tue, May 15, 2012 at 2:15 AM, Timon Gehr mailto:timon.g..

Re: arrays: if(null == [ ])

2012-05-15 Thread Gor Gyolchanyan
On Tue, May 15, 2012 at 2:34 AM, Jonathan M Davis wrote: > On Tuesday, May 15, 2012 00:48:41 Gor Gyolchanyan wrote: > > >> P.S. Please don't top-post. It's bad etiquette and makes posts harder > to > > >> follow. > > > > It's not me. It's how gmail works. > > Just because gmail puts your cursor at

Re: arrays: if(null == [ ])

2012-05-15 Thread Gor Gyolchanyan
There's not reason to use printf! This is ridiculous! We haev a type-safe writef, which does exactly that and does it better. Besides, wrapping the literal into a toUTFz is not too difficult! On Tue, May 15, 2012 at 2:15 AM, Timon Gehr wrote: > On 05/14/2012 07:16 PM, Gor Gyolchanyan wrote: > >>

Re: arrays: if(null == [ ])

2012-05-15 Thread deadalnix
Le 14/05/2012 21:53, Steven Schveighoffer a écrit : On Mon, 14 May 2012 15:30:25 -0400, deadalnix wrote: Le 14/05/2012 16:37, Steven Schveighoffer a écrit : Note that [] is a request to the runtime to build an empty array. The runtime detects this, and rather than consuming a heap allocation

Re: arrays: if(null == [ ])

2012-05-14 Thread Jonathan M Davis
On Tuesday, May 15, 2012 00:48:41 Gor Gyolchanyan wrote: > >> P.S. Please don't top-post. It's bad etiquette and makes posts harder to > >> follow. > > It's not me. It's how gmail works. Just because gmail puts your cursor at the top of your reply by default doesn't mean that you have to write y

Re: arrays: if(null == [ ])

2012-05-14 Thread Timon Gehr
On 05/14/2012 07:16 PM, Gor Gyolchanyan wrote: At least we could make an empty string a null array of characters for consistency. How many times did anyone use the feature of string literals being null-terminated? It is a useful feature. There is no reason to break printf("Hello, World!");

Re: arrays: if(null == [ ])

2012-05-14 Thread Timon Gehr
On 05/14/2012 01:51 PM, deadalnix wrote: Le 14/05/2012 12:49, Gor Gyolchanyan a écrit : So, null arrays and empty arrays are always the same, except for an empty string, which is a valid non-nill array of characters with length 0, right? If it is the current behavior, it deserve a WAT ! I a

Re: arrays: if(null == [ ])

2012-05-14 Thread Gor Gyolchanyan
>> P.S. Please don't top-post. It's bad etiquette and makes posts harder to follow. It's not me. It's how gmail works. On Tue, May 15, 2012 at 12:12 AM, Jonathan M Davis wrote: > On Monday, May 14, 2012 21:16:21 Gor Gyolchanyan wrote: > > At least we could make an empty string a null array of ch

Re: arrays: if(null == [ ])

2012-05-14 Thread Jonathan M Davis
On Monday, May 14, 2012 21:16:21 Gor Gyolchanyan wrote: > At least we could make an empty string a null array of characters for > consistency. It's completely consintent. If there is memory allocated for the array, then it's ptr property is non-null, and then the array is non-null per the is ope

Re: arrays: if(null == [ ])

2012-05-14 Thread Steven Schveighoffer
On Mon, 14 May 2012 15:30:25 -0400, deadalnix wrote: Le 14/05/2012 16:37, Steven Schveighoffer a écrit : Note that [] is a request to the runtime to build an empty array. The runtime detects this, and rather than consuming a heap allocation to build nothing, it simply returns a null-pointed ar

Re: arrays: if(null == [ ])

2012-05-14 Thread deadalnix
Le 14/05/2012 16:37, Steven Schveighoffer a écrit : Note that [] is a request to the runtime to build an empty array. The runtime detects this, and rather than consuming a heap allocation to build nothing, it simply returns a null-pointed array. This is 100% the right decision, and I don't think

Re: arrays: if(null == [ ])

2012-05-14 Thread Gor Gyolchanyan
This is the original thread and there's no reply from you prior to this one. On Mon, May 14, 2012 at 9:41 PM, Alex Rønne Petersen wrote: > On 14-05-2012 19:16, Gor Gyolchanyan wrote: > >> At least we could make an empty string a null array of characters for >> consistency. How many times did anyo

Re: arrays: if(null == [ ])

2012-05-14 Thread Alex Rønne Petersen
On 14-05-2012 19:16, Gor Gyolchanyan wrote: At least we could make an empty string a null array of characters for consistency. How many times did anyone use the feature of string literals being null-terminated? On Mon, May 14, 2012 at 8:56 PM, Jonathan M Davis mailto:jmdavisp...@gmx.com>> wrote:

Re: arrays: if(null == [ ])

2012-05-14 Thread Gor Gyolchanyan
At least we could make an empty string a null array of characters for consistency. How many times did anyone use the feature of string literals being null-terminated? On Mon, May 14, 2012 at 8:56 PM, Jonathan M Davis wrote: > On Monday, May 14, 2012 14:08:17 Gor Gyolchanyan wrote: > > Hi! I have

Re: arrays: if(null == [ ])

2012-05-14 Thread Jonathan M Davis
On Monday, May 14, 2012 14:08:17 Gor Gyolchanyan wrote: > Hi! I have a small question: > Is the test for a null array equivalent to a test for zero-length array? > This is particularly interesting for strings. > For instance, I could return an empty string from a toString-like function > and the em

Re: arrays: if(null == [ ])

2012-05-14 Thread Steven Schveighoffer
On Mon, 14 May 2012 06:08:17 -0400, Gor Gyolchanyan wrote: Hi! I have a small question: Is the test for a null array equivalent to a test for zero-length array? == tests for length and content equivalence. 'is' tests for both pointer and length equivalence (and therefore, content equalit

Re: arrays: if(null == [ ])

2012-05-14 Thread Gor Gyolchanyan
No, it doesn't. Appending to a null array is equivalent to allocating a new array. On Mon, May 14, 2012 at 6:29 PM, H. S. Teoh wrote: > On Mon, May 14, 2012 at 05:00:25PM +0400, Gor Gyolchanyan wrote: > > I think any kind of null array should be different from an array of > > zero length. > > Bu

Re: arrays: if(null == [ ])

2012-05-14 Thread H. S. Teoh
On Mon, May 14, 2012 at 05:00:25PM +0400, Gor Gyolchanyan wrote: > I think any kind of null array should be different from an array of > zero length. But that defeats the utility of idioms like: int[] arr; arr ~= 123; ... T -- There are four kinds of lies: lies, damn l

Re: arrays: if(null == [ ])

2012-05-14 Thread Gor Gyolchanyan
I think any kind of null array should be different from an array of zero length. On Mon, May 14, 2012 at 3:55 PM, simendsjo wrote: > On Mon, 14 May 2012 13:51:40 +0200, deadalnix wrote: > > Le 14/05/2012 12:49, Gor Gyolchanyan a écrit : >> >>> So, null arrays and empty arrays are always the sa

Re: arrays: if(null == [ ])

2012-05-14 Thread simendsjo
On Mon, 14 May 2012 13:51:40 +0200, deadalnix wrote: Le 14/05/2012 12:49, Gor Gyolchanyan a écrit : So, null arrays and empty arrays are always the same, except for an empty string, which is a valid non-nill array of characters with length 0, right? If it is the current behavior, it deserve

Re: arrays: if(null == [ ])

2012-05-14 Thread deadalnix
Le 14/05/2012 12:49, Gor Gyolchanyan a écrit : So, null arrays and empty arrays are always the same, except for an empty string, which is a valid non-nill array of characters with length 0, right? If it is the current behavior, it deserve a WAT !

Re: arrays: if(null == [ ])

2012-05-14 Thread Gor Gyolchanyan
So, null arrays and empty arrays are always the same, except for an empty string, which is a valid non-nill array of characters with length 0, right? On Mon, May 14, 2012 at 2:24 PM, simendsjo wrote: > On Mon, 14 May 2012 12:08:17 +0200, Gor Gyolchanyan < > gor.f.gyolchan...@gmail.com> wrote: >

Re: arrays: if(null == [ ])

2012-05-14 Thread Simen Kjaeraas
On Mon, 14 May 2012 12:08:17 +0200, Gor Gyolchanyan wrote: Hi! I have a small question: Is the test for a null array equivalent to a test for zero-length array? This is particularly interesting for strings. For instance, I could return an empty string from a toString-like function and the

Re: arrays: if(null == [ ])

2012-05-14 Thread simendsjo
On Mon, 14 May 2012 12:08:17 +0200, Gor Gyolchanyan wrote: Hi! I have a small question: Is the test for a null array equivalent to a test for zero-length array? This is particularly interesting for strings. For instance, I could return an empty string from a toString-like function and the

arrays: if(null == [ ])

2012-05-14 Thread Gor Gyolchanyan
Hi! I have a small question: Is the test for a null array equivalent to a test for zero-length array? This is particularly interesting for strings. For instance, I could return an empty string from a toString-like function and the empty string would be printed, but If I returned a null string, that