Re: What about putting array.empty in object.d?

2012-03-25 Thread Jacob Carlborg
On 2012-03-21 23:25, Simen Kjærås wrote: I hope you mean canFind!(true)([3, 4, 5]);. canFind!a fails for arrays where all elements are 0. Yes. I'm not really familiar with canFind or std.algorithms in general. -- /Jacob Carlborg

Re: What about putting array.empty in object.d?

2012-03-22 Thread Steven Schveighoffer
On Wed, 21 Mar 2012 20:53:42 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: On Wednesday, March 21, 2012 20:46:05 Jonathan M Davis wrote: On Wednesday, March 21, 2012 20:17:06 Steven Schveighoffer wrote: On Wed, 21 Mar 2012 19:56:41 -0400, Jonathan M Davis jmdavisp...@gmx.com

Re: What about putting array.empty in object.d?

2012-03-22 Thread Jonathan M Davis
On Thursday, March 22, 2012 07:12:22 Steven Schveighoffer wrote: Note that the default std::list has O(1) length (as does dcollections' LinkedList). It's not as inevitable as you think. It depends on bothe container its implementation as to how efficient length/size is (and in the case of

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jacob Carlborg
On 2012-03-21 04:54, Nick Sabalausky wrote: Hear me out... ;) Using empty seems to be emerging as the recommended practice for testing whether an array is empty. And that makes sense as it's consistent with other ranges. I'm all in favor of that. But I've found myself avoiding empty (and

Re: What about putting array.empty in object.d?

2012-03-21 Thread Nick Sabalausky
Jacob Carlborg d...@me.com wrote in message news:jkc321$25pv$1...@digitalmars.com... On 2012-03-21 04:54, Nick Sabalausky wrote: Hear me out... ;) Using empty seems to be emerging as the recommended practice for testing whether an array is empty. And that makes sense as it's consistent with

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jacob Carlborg
On 2012-03-21 09:42, Nick Sabalausky wrote: Jacob Carlborgd...@me.com wrote in message Sure, why not. Do we want an any function as well, that is the opposite? I think !array.empty is plenty sufficient. Besides, there are other good uses of any that have been brought up before. Actually I

Re: What about putting array.empty in object.d?

2012-03-21 Thread Steven Schveighoffer
On Wed, 21 Mar 2012 00:54:51 -0400, Daniel Murphy yebbl...@nospamgmail.com wrote: FWIW, I would rather see `if (array)` translated to `if (array.length)` and this become the recomended way to check if an array is empty. Wouldn't that remove the dependency on std.array for most of the

Re: What about putting array.empty in object.d?

2012-03-21 Thread Xinok
On Wednesday, 21 March 2012 at 04:54:54 UTC, Daniel Murphy wrote: FWIW, I would rather see `if (array)` translated to `if (array.length)` and this become the recomended way to check if an array is empty. Wouldn't that remove the dependency on std.array for most of the cases? Nope. .length

Re: What about putting array.empty in object.d?

2012-03-21 Thread Steven Schveighoffer
On Wed, 21 Mar 2012 11:50:46 -0400, Xinok xi...@live.com wrote: On Wednesday, 21 March 2012 at 04:54:54 UTC, Daniel Murphy wrote: FWIW, I would rather see `if (array)` translated to `if (array.length)` and this become the recomended way to check if an array is empty. Wouldn't that remove

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jonathan M Davis
On Wednesday, March 21, 2012 15:54:51 Daniel Murphy wrote: FWIW, I would rather see `if (array)` translated to `if (array.length)` and this become the recomended way to check if an array is empty. Wouldn't that remove the dependency on std.array for most of the cases? The problem with checking

Re: What about putting array.empty in object.d?

2012-03-21 Thread Steven Schveighoffer
On Wed, 21 Mar 2012 14:33:58 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: On Wednesday, March 21, 2012 15:54:51 Daniel Murphy wrote: FWIW, I would rather see `if (array)` translated to `if (array.length)` and this become the recomended way to check if an array is empty. Wouldn't

Re: What about putting array.empty in object.d?

2012-03-21 Thread Nick Sabalausky
Steven Schveighoffer schvei...@yahoo.com wrote in message news:op.wbjc7au8eav7ka@localhost.localdomain... I don't see why defining empty in object.d is necessary for things that don't involve ranges at all. But arrays *are* ranges. Or at least they're supposed to be. Any time you import a

Re: What about putting array.empty in object.d?

2012-03-21 Thread Steven Schveighoffer
On Wed, 21 Mar 2012 16:21:21 -0400, Nick Sabalausky a@a.a wrote: Steven Schveighoffer schvei...@yahoo.com wrote in message news:op.wbjc7au8eav7ka@localhost.localdomain... I don't see why defining empty in object.d is necessary for things that don't involve ranges at all. But arrays *are*

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jonathan M Davis
On Wednesday, March 21, 2012 10:17:08 Jacob Carlborg wrote: On 2012-03-21 09:42, Nick Sabalausky wrote: Jacob Carlborgd...@me.com wrote in message Sure, why not. Do we want an any function as well, that is the opposite? I think !array.empty is plenty sufficient. Besides, there are

Re: What about putting array.empty in object.d?

2012-03-21 Thread Steven Schveighoffer
On Wed, 21 Mar 2012 16:43:28 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: On Wed, 21 Mar 2012 16:21:21 -0400, Nick Sabalausky a@a.a wrote: Steven Schveighoffer schvei...@yahoo.com wrote in message news:op.wbjc7au8eav7ka@localhost.localdomain... As an bonus this gets rid of the

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jonathan M Davis
On Wednesday, March 21, 2012 15:46:12 Steven Schveighoffer wrote: On Wed, 21 Mar 2012 14:33:58 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: On Wednesday, March 21, 2012 15:54:51 Daniel Murphy wrote: FWIW, I would rather see `if (array)` translated to `if (array.length)` and this

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jacob Carlborg
On 2012-03-21 21:49, Jonathan M Davis wrote: On Wednesday, March 21, 2012 10:17:08 Jacob Carlborg wrote: http://www.ruby-doc.org/core-1.8.7/Enumerable.html#method-i-any-3F So, std.algorithm.canFind then? There has been some discussion of renaming it to any (or at least the overload that just

Re: What about putting array.empty in object.d?

2012-03-21 Thread Simen Kjærås
On Wed, 21 Mar 2012 22:30:17 +0100, Jacob Carlborg d...@me.com wrote: On 2012-03-21 21:49, Jonathan M Davis wrote: On Wednesday, March 21, 2012 10:17:08 Jacob Carlborg wrote: http://www.ruby-doc.org/core-1.8.7/Enumerable.html#method-i-any-3F So, std.algorithm.canFind then? There has been

Re: What about putting array.empty in object.d?

2012-03-21 Thread Daniel Murphy
Jonathan M Davis jmdavisp...@gmx.com wrote in message news:mailman.985.1332364578.4860.digitalmar...@puremagic.com... I know that. Much point is that length == 0 is a bad thing to do in general, because it's ineffecient with some containers. The language itself is pretty much irrelevant as

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jonathan M Davis
On Thursday, March 22, 2012 10:39:23 Daniel Murphy wrote: Jonathan M Davis jmdavisp...@gmx.com wrote in message news:mailman.985.1332364578.4860.digitalmar...@puremagic.com... I know that. Much point is that length == 0 is a bad thing to do in general, because it's ineffecient with some

Re: What about putting array.empty in object.d?

2012-03-21 Thread Steven Schveighoffer
On Wed, 21 Mar 2012 19:56:41 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: Except that containers shouldn't provide indexing if it's not efficient. And from what I've seen, it's far too common for programmers to check length == 0, and they end up doing it on stuff like linked lists

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jonathan M Davis
On Wednesday, March 21, 2012 20:17:06 Steven Schveighoffer wrote: On Wed, 21 Mar 2012 19:56:41 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: Except that containers shouldn't provide indexing if it's not efficient. And from what I've seen, it's far too common for programmers to check

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jonathan M Davis
On Wednesday, March 21, 2012 20:46:05 Jonathan M Davis wrote: On Wednesday, March 21, 2012 20:17:06 Steven Schveighoffer wrote: On Wed, 21 Mar 2012 19:56:41 -0400, Jonathan M Davis jmdavisp...@gmx.com wrote: Except that containers shouldn't provide indexing if it's not efficient. And

Re: What about putting array.empty in object.d?

2012-03-21 Thread Andrei Alexandrescu
On 3/21/12 6:56 PM, Jonathan M Davis wrote: Except that containers shouldn't provide indexing if it's not efficient. And from what I've seen, it's far too common for programmers to check length == 0, and they end up doing it on stuff like linked lists where it _is_ inefficient. It's considered

Re: What about putting array.empty in object.d?

2012-03-21 Thread Andrei Alexandrescu
On 3/21/12 7:53 PM, Jonathan M Davis wrote: Actually, it looks like std.container _does_ guarantee that length is O(1), unlike C++'s STL, in which case it's not the same issue that it is in C++. Here we learned from a small mistake of C++. (BTW it's O(log n).) Andrei

Re: What about putting array.empty in object.d?

2012-03-21 Thread Jonathan M Davis
On Wednesday, March 21, 2012 21:12:36 Andrei Alexandrescu wrote: On 3/21/12 7:53 PM, Jonathan M Davis wrote: Actually, it looks like std.container _does_ guarantee that length is O(1), unlike C++'s STL, in which case it's not the same issue that it is in C++. Here we learned from a small

What about putting array.empty in object.d?

2012-03-20 Thread Nick Sabalausky
Hear me out... ;) Using empty seems to be emerging as the recommended practice for testing whether an array is empty. And that makes sense as it's consistent with other ranges. I'm all in favor of that. But I've found myself avoiding empty (and instead doing arr== or checking the .length)

Re: What about putting array.empty in object.d?

2012-03-20 Thread Andrej Mitrovic
On 3/21/12, Nick Sabalausky a@a.a wrote: Hear me out... ;) Man I would say the same thing about write() functions. I've missed importing std.stdio so many times. It doesn't help that the compiler happily asks me if I've missed an import to std.stdio. But I digress.. I use .length all the time.

Re: What about putting array.empty in object.d?

2012-03-20 Thread H. S. Teoh
On Wed, Mar 21, 2012 at 05:27:01AM +0100, Andrej Mitrovic wrote: On 3/21/12, Nick Sabalausky a@a.a wrote: Hear me out... ;) Man I would say the same thing about write() functions. I've missed importing std.stdio so many times. It doesn't help that the compiler happily asks me if I've

Re: What about putting array.empty in object.d?

2012-03-20 Thread Daniel Murphy
FWIW, I would rather see `if (array)` translated to `if (array.length)` and this become the recomended way to check if an array is empty. Wouldn't that remove the dependency on std.array for most of the cases?