Re: in not working for arrays is silly, change my view

2020-03-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 02, 2020 at 07:51:34PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > On 3/2/20 6:46 PM, H. S. Teoh wrote: > > To prevent the optimizer from eliding "useless" code, you need to do > > something with the return value that isn't trivial (assigning to a > > variable

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 7:32 PM, aliak wrote: On Monday, 2 March 2020 at 23:27:22 UTC, Steven Schveighoffer wrote: What I think is happening is that it determines nobody is using the result, and the function is pure, so it doesn't bother calling that function (probably not even the lambda, and then

Re: in not working for arrays is silly, change my view

2020-03-02 Thread aliak via Digitalmars-d-learn
On Monday, 2 March 2020 at 23:27:22 UTC, Steven Schveighoffer wrote: What I think is happening is that it determines nobody is using the result, and the function is pure, so it doesn't bother calling that function (probably not even the lambda, and then probably removes the loop completely).

Re: in not working for arrays is silly, change my view

2020-03-02 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Mar 02, 2020 at 06:27:22PM -0500, Steven Schveighoffer via Digitalmars-d-learn wrote: [...] > Yeah, this looked very fishy to me. ldc can do some nasty "helpful" > things to save you time! When I posted my results, I was using DMD. > > I used run.dlang.io with ldc, and verified I get the

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 5:21 PM, aliak wrote: On Monday, 2 March 2020 at 21:33:37 UTC, Steven Schveighoffer wrote: On 3/2/20 3:52 PM, aliak wrote: On Monday, 2 March 2020 at 15:47:26 UTC, Steven Schveighoffer wrote: On 3/2/20 6:52 AM, Andrea Fontana wrote: On Saturday, 29 February 2020 at 20:11:24 UTC,

Re: in not working for arrays is silly, change my view

2020-03-02 Thread aliak via Digitalmars-d-learn
On Monday, 2 March 2020 at 21:33:37 UTC, Steven Schveighoffer wrote: On 3/2/20 3:52 PM, aliak wrote: On Monday, 2 March 2020 at 15:47:26 UTC, Steven Schveighoffer wrote: On 3/2/20 6:52 AM, Andrea Fontana wrote: On Saturday, 29 February 2020 at 20:11:24 UTC, Steven Schveighoffer wrote: 1. in

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 3:52 PM, aliak wrote: On Monday, 2 March 2020 at 15:47:26 UTC, Steven Schveighoffer wrote: On 3/2/20 6:52 AM, Andrea Fontana wrote: On Saturday, 29 February 2020 at 20:11:24 UTC, Steven Schveighoffer wrote: 1. in is supposed to be O(lg(n)) or better. Generic code may depend on this

Re: in not working for arrays is silly, change my view

2020-03-02 Thread aliak via Digitalmars-d-learn
On Monday, 2 March 2020 at 15:47:26 UTC, Steven Schveighoffer wrote: On 3/2/20 6:52 AM, Andrea Fontana wrote: On Saturday, 29 February 2020 at 20:11:24 UTC, Steven Schveighoffer wrote: 1. in is supposed to be O(lg(n)) or better. Generic code may depend on this property. Searching an array is

Re: in not working for arrays is silly, change my view

2020-03-02 Thread aliak via Digitalmars-d-learn
On Monday, 2 March 2020 at 15:50:08 UTC, Steven Schveighoffer wrote: On 3/2/20 6:39 AM, JN wrote: On Saturday, 29 February 2020 at 21:56:51 UTC, Ali Çehreli wrote: Because you mentioned canFind, I think you want the semantics to be "is there an element with this value." If so, it would be

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 6:39 AM, JN wrote: On Saturday, 29 February 2020 at 21:56:51 UTC, Ali Çehreli wrote: Because you mentioned canFind, I think you want the semantics to be "is there an element with this value." If so, it would be confusing to use the same operator for two different things: For

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/2/20 6:52 AM, Andrea Fontana wrote: On Saturday, 29 February 2020 at 20:11:24 UTC, Steven Schveighoffer wrote: 1. in is supposed to be O(lg(n)) or better. Generic code may depend on this property. Searching an array is O(n). Probably it should work if we're using a "SortedRange". int[]

Re: in not working for arrays is silly, change my view

2020-03-02 Thread Andrea Fontana via Digitalmars-d-learn
On Saturday, 29 February 2020 at 20:11:24 UTC, Steven Schveighoffer wrote: 1. in is supposed to be O(lg(n)) or better. Generic code may depend on this property. Searching an array is O(n). Probably it should work if we're using a "SortedRange". int[] a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; auto

Re: in not working for arrays is silly, change my view

2020-03-02 Thread JN via Digitalmars-d-learn
On Saturday, 29 February 2020 at 21:56:51 UTC, Ali Çehreli wrote: Because you mentioned canFind, I think you want the semantics to be "is there an element with this value." If so, it would be confusing to use the same operator for two different things: For associative arrays, it means "is

Re: in not working for arrays is silly, change my view

2020-02-29 Thread Ali Çehreli via Digitalmars-d-learn
On 2/29/20 11:38 AM, JN wrote: > assert(1 in [1, 2, 3]); Because you mentioned canFind, I think you want the semantics to be "is there an element with this value." If so, it would be confusing to use the same operator for two different things: For associative arrays, it means "is there an

Re: in not working for arrays is silly, change my view

2020-02-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/29/20 2:38 PM, JN wrote: assert(1 in [1, 2, 3]); Error: incompatible types for (1) in ([1, 2, 3]): int and int[ Yes, I know about .canFind(), but this is something that trips people over and over. I think it would be better if "in" worked for both assoc arrays and normal arrays, or