Jump to page: 1 2
Thread overview
Remove instance from array
Jul 05, 2017
Jolly James
Jul 05, 2017
Andrea Fontana
Jul 05, 2017
Igor Shirkalin
Jul 05, 2017
Jolly James
Jul 05, 2017
Igor Shirkalin
Jul 05, 2017
Jolly James
Jul 05, 2017
Igor Shirkalin
Jul 05, 2017
Jolly James
Jul 06, 2017
Andrea Fontana
Jul 06, 2017
Jolly James
Jul 05, 2017
bachmeier
Jul 05, 2017
Jolly James
Jul 05, 2017
H. S. Teoh
Aug 05, 2017
Igor Shirkalin
July 05, 2017
> WhatEver[] q = [];
>
> [...]
>
> auto i = new WhatEver();
> q[] = i;
>

How does one remove that instance 'i'?
July 05, 2017
On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:
>> WhatEver[] q = [];
>>
>> [...]
>>
>> auto i = new WhatEver();
>> q[] = i;
>>
>
> How does one remove that instance 'i'?

Maybe: http://dlang.org/phobos/std_algorithm_mutation.html#.remove

?
July 05, 2017
On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:
>> WhatEver[] q = [];
>>
>> [...]
>>
>> auto i = new WhatEver();
>> q[] = i;
>>
>
> How does one remove that instance 'i'?

What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.
July 05, 2017
On Wednesday, 5 July 2017 at 15:44:47 UTC, Igor Shirkalin wrote:
> On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:
>>> WhatEver[] q = [];
>>>
>>> [...]
>>>
>>> auto i = new WhatEver();
>>> q[] = i;
>>>
>>
>> How does one remove that instance 'i'?
>
> What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.

I would like to know how works: removing
 - the first
 - and all
references to 'i' inside the 'q'.
July 05, 2017
On Wednesday, 5 July 2017 at 15:48:14 UTC, Jolly James wrote:
> On Wednesday, 5 July 2017 at 15:44:47 UTC, Igor Shirkalin wrote:
>> On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:
>>>> WhatEver[] q = [];
>>>>
>>>> [...]
>>>>
>>>> auto i = new WhatEver();
>>>> q[] = i;
>>>>
>>>
>>> How does one remove that instance 'i'?
>>
>> What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.
>
> I would like to know how works: removing
>  - the first
>  - and all
> references to 'i' inside the 'q'.

Perhaps, for all references to i it should look like:
a = a.filter!(a => a !is i).array;
July 05, 2017
On Wednesday, 5 July 2017 at 15:56:45 UTC, Igor Shirkalin wrote:
> On Wednesday, 5 July 2017 at 15:48:14 UTC, Jolly James wrote:
>> On Wednesday, 5 July 2017 at 15:44:47 UTC, Igor Shirkalin wrote:
>>> On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:
>>>>> WhatEver[] q = [];
>>>>>
>>>>> [...]
>>>>>
>>>>> auto i = new WhatEver();
>>>>> q[] = i;
>>>>>
>>>>
>>>> How does one remove that instance 'i'?
>>>
>>> What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.
>>
>> I would like to know how works: removing
>>  - the first
>>  - and all
>> references to 'i' inside the 'q'.
>
> Perhaps, for all references to i it should look like:
> a = a.filter!(a => a !is i).array;

Thank you! :)


But why a containers so complicated in D?

In C# I would go for a generic List<T>, which would support structs and classes, where I simply could call '.Remove(T item)' or '.RemoveAt(int index)'. I would know how this works, because the method names make sense, the docs are straight forward.

Here in D everything looks like climbing mount everest. When you ask how to use D's containers you are recommended to use dynamic arrays instead. When you look at the docs for std.algorithm, e.g. the .remove section, you get bombed with things like 'SwapStrategy.unstable', asserts and tuples, but you aren't told how to simply remove 1 specific element.
July 05, 2017
On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote:
> On Wednesday, 5 July 2017 at 15:56:45 UTC, Igor Shirkalin wrote:
>> On Wednesday, 5 July 2017 at 15:48:14 UTC, Jolly James wrote:
>>> On Wednesday, 5 July 2017 at 15:44:47 UTC, Igor Shirkalin wrote:
>>>> On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:
>>>>>> WhatEver[] q = [];
>>>>>>
>>>>>> [...]
>>>>>>
>>>>>> auto i = new WhatEver();
>>>>>> q[] = i;
>>>>>>
>>>>>
>>>>> How does one remove that instance 'i'?
>>>>
>>>> What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.
>>>
>>> I would like to know how works: removing
>>>  - the first
>>>  - and all
>>> references to 'i' inside the 'q'.
>>
>> Perhaps, for all references to i it should look like:
>> a = a.filter!(a => a !is i).array;
>
> Thank you! :)
>
>
> But why a containers so complicated in D?
>
> In C# I would go for a generic List<T>, which would support structs and classes, where I simply could call '.Remove(T item)' or '.RemoveAt(int index)'. I would know how this works, because the method names make sense, the docs are straight forward.
>
> Here in D everything looks like climbing mount everest. When you ask how to use D's containers you are recommended to use dynamic arrays instead. When you look at the docs for std.algorithm, e.g. the .remove section, you get bombed with things like 'SwapStrategy.unstable', asserts and tuples, but you aren't told how to simply remove 1 specific element.

I don't know c sharp, but I can tell everything about c++ and python. To climb a everest in python you have to know almost nothing, in c++ you have to know almost everything. In D you have to be smarter, you do not need to climb a everest but you have to know minimum to do that. Spend a year in learning and get the best result in minutes).
July 05, 2017
On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote:
> On Wednesday, 5 July 2017 at 15:56:45 UTC, Igor Shirkalin wrote:
>> [...]
>
> Thank you! :)
>
>
> But why a containers so complicated in D?
>
> [...]



Part of CoreCLR's 'List<T>':

>        public bool Remove(T item)
>        {
>            int index = IndexOf(item);
>            if (index >= 0)
>            {
>                RemoveAt(index);
>                return true;
>            }
>
>            return false;
>        }
> // https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Collections/Generic/List.cs


If there isn't already, maybe something similar to this should get part of Phobos. I think this could be really useful.
July 05, 2017
On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote:

> Here in D everything looks like climbing mount everest. When you ask how to use D's containers you are recommended to use dynamic arrays instead. When you look at the docs for std.algorithm, e.g. the .remove section, you get bombed with things like 'SwapStrategy.unstable', asserts and tuples, but you aren't told how to simply remove 1 specific element.

If you feel that there is a problem with the docs, you should file a bug: https://dlang.org/bugstats.php

The documentation is still not perfect, but the only way to improve it is to file bugs when you see something that needs fixing.
July 05, 2017
On Wednesday, 5 July 2017 at 16:55:43 UTC, bachmeier wrote:
> On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote:
>
>> Here in D everything looks like climbing mount everest. When you ask how to use D's containers you are recommended to use dynamic arrays instead. When you look at the docs for std.algorithm, e.g. the .remove section, you get bombed with things like 'SwapStrategy.unstable', asserts and tuples, but you aren't told how to simply remove 1 specific element.
>
> If you feel that there is a problem with the docs, you should file a bug: https://dlang.org/bugstats.php
>
> The documentation is still not perfect, but the only way to improve it is to file bugs when you see something that needs fixing.

unfortunately, it's not that the docs would be wrong or something that can be easily corrected. Nope, the docs do everything right, they show you what the existing things do. But what they don't do is how to get stuff done. imho some additional, useful guides would be nice.
« First   ‹ Prev
1 2