digitalmars.D.learn - Remove instance from array
- Jolly James (1/5) Jul 05 2017 How does one remove that instance 'i'?
- Andrea Fontana (3/11) Jul 05 2017 Maybe: http://dlang.org/phobos/std_algorithm_mutation.html#.remove
- Igor Shirkalin (3/11) Jul 05 2017 What exactly do you want to remove? After a[]=i your array
- Jolly James (5/17) Jul 05 2017 I would like to know how works: removing
- Igor Shirkalin (3/21) Jul 05 2017 Perhaps, for all references to i it should look like:
- Jolly James (13/36) Jul 05 2017 Thank you! :)
- Igor Shirkalin (7/45) Jul 05 2017 I don't know c sharp, but I can tell everything about c++ and
- Jolly James (4/21) Jul 05 2017 If there isn't already, maybe something similar to this should
- Andrea Fontana (4/31) Jul 06 2017 q = q.remove(1); // Remove element with index 1
- Jolly James (2/18) Jul 06 2017 thx
- bachmeier (6/12) Jul 05 2017 If you feel that there is a problem with the docs, you should
- Jolly James (6/18) Jul 05 2017 unfortunately, it's not that the docs would be wrong or something
- H. S. Teoh via Digitalmars-d-learn (22/42) Jul 05 2017 No, that's a sign that the docs are not good enough. Describing what
- Igor Shirkalin (7/45) Aug 05 2017 I don't know c sharp, but I can tell everything about c++ and
WhatEver[] q = []; [...] auto i = new WhatEver(); q[] = i;How does one remove that instance 'i'?
Jul 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'?
Jul 05 2017
On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.WhatEver[] q = []; [...] auto i = new WhatEver(); q[] = i;How does one remove that instance 'i'?
Jul 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:I would like to know how works: removing - the first - and all references to 'i' inside the 'q'.What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.WhatEver[] q = []; [...] auto i = new WhatEver(); q[] = i;How does one remove that instance 'i'?
Jul 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:Perhaps, for all references to i it should look like: a = a.filter!(a => a !is i).array;On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:I would like to know how works: removing - the first - and all references to 'i' inside the 'q'.What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.WhatEver[] q = []; [...] auto i = new WhatEver(); q[] = i;How does one remove that instance 'i'?
Jul 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:Thank you! :) But why a containers so complicated in D? 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.On Wednesday, 5 July 2017 at 15:44:47 UTC, Igor Shirkalin wrote:Perhaps, for all references to i it should look like: a = a.filter!(a => a !is i).array;On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:I would like to know how works: removing - the first - and all references to 'i' inside the 'q'.What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.WhatEver[] q = []; [...] auto i = new WhatEver(); q[] = i;How does one remove that instance 'i'?
Jul 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: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).On Wednesday, 5 July 2017 at 15:48:14 UTC, Jolly James wrote:Thank you! :) But why a containers so complicated in D? 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.On Wednesday, 5 July 2017 at 15:44:47 UTC, Igor Shirkalin wrote:Perhaps, for all references to i it should look like: a = a.filter!(a => a !is i).array;On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:I would like to know how works: removing - the first - and all references to 'i' inside the 'q'.What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.WhatEver[] q = []; [...] auto i = new WhatEver(); q[] = i;How does one remove that instance 'i'?
Jul 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:Part of CoreCLR's 'List<T>':[...]Thank you! :) But why a containers so complicated in D? [...]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.csIf there isn't already, maybe something similar to this should get part of Phobos. I think this could be really useful.
Jul 05 2017
On Wednesday, 5 July 2017 at 16:17:29 UTC, Jolly James wrote:On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote:q = q.remove(1); // Remove element with index 1 q = q.remove(x => x == instance); // Remove all items that match instanceOn Wednesday, 5 July 2017 at 15:56:45 UTC, Igor Shirkalin wrote:Part of CoreCLR's 'List<T>':[...]Thank you! :) But why a containers so complicated in D? [...]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.csIf there isn't already, maybe something similar to this should get part of Phobos. I think this could be really useful.
Jul 06 2017
On Thursday, 6 July 2017 at 08:15:10 UTC, Andrea Fontana wrote:On Wednesday, 5 July 2017 at 16:17:29 UTC, Jolly James wrote:thxOn Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote:q = q.remove(1); // Remove element with index 1 q = q.remove(x => x == instance); // Remove all items that match instance[...]Part of CoreCLR's 'List<T>':[...]If there isn't already, maybe something similar to this should get part of Phobos. I think this could be really useful.
Jul 06 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.
Jul 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: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.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.
Jul 05 2017
On Wed, Jul 05, 2017 at 05:07:14PM +0000, Jolly James via Digitalmars-d-learn wrote:On Wednesday, 5 July 2017 at 16:55:43 UTC, bachmeier wrote:No, that's a sign that the docs are not good enough. Describing what existing things do is only the bare minimum of documentation. *Good* documentation should also tell you what you can use it for, and give examples of how to do it, preferably examples that address the most common use cases first, and then, if necessary, a discussion of more details later. The very first example in the docs for std.algorithm.mutation.remove is not suitable as a first example, because it already throws something unexpected in your face, i.e., that remove() doesn't change the incoming range directly. It should have shown the *correct* way of removing an element as a first example, i.e.: a = a.remove(1); And *then* talk about the details later. Here's my fix for this: https://github.com/dlang/phobos/pull/5548 In the future, please do file a bug for these kinds of documentation issues. D needs *good* documentation, not just bare-minimum documentation. T -- Long, long ago, the ancient Chinese invented a device that lets them see through walls. It was called the "window".On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote: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.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.
Jul 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: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).On Wednesday, 5 July 2017 at 15:48:14 UTC, Jolly James wrote:Thank you! :) But why a containers so complicated in D? 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.On Wednesday, 5 July 2017 at 15:44:47 UTC, Igor Shirkalin wrote:Perhaps, for all references to i it should look like: a = a.filter!(a => a !is i).array;On Wednesday, 5 July 2017 at 15:30:08 UTC, Jolly James wrote:I would like to know how works: removing - the first - and all references to 'i' inside the 'q'.What exactly do you want to remove? After a[]=i your array contain a lot of references to 'i'.WhatEver[] q = []; [...] auto i = new WhatEver(); q[] = i;How does one remove that instance 'i'?
Aug 05 2017