Re: Remove instance from array

2017-08-05 Thread Igor Shirkalin via Digitalmars-d-learn

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, 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).


Re: Remove instance from array

2017-07-06 Thread Jolly James via Digitalmars-d-learn

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:

On Wednesday, 5 July 2017 at 16:04:16 UTC, Jolly James wrote:

[...]




Part of CoreCLR's 'List':


[...]



If there isn't already, maybe something similar to this should 
get part of Phobos. I think this could be really useful.


q = q.remove(1); // Remove element with index 1
q = q.remove(x => x == instance); // Remove all items that 
match instance


thx


Re: Remove instance from array

2017-07-06 Thread Andrea Fontana via Digitalmars-d-learn

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:
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':


   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.


q = q.remove(1); // Remove element with index 1
q = q.remove(x => x == instance); // Remove all items that match 
instance


Re: Remove instance from array

2017-07-05 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jul 05, 2017 at 05:07:14PM +, Jolly James via Digitalmars-d-learn 
wrote:
> 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.

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".


Re: Remove instance from array

2017-07-05 Thread Jolly James via Digitalmars-d-learn

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.


Re: Remove instance from array

2017-07-05 Thread bachmeier via Digitalmars-d-learn

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.


Re: Remove instance from array

2017-07-05 Thread Jolly James via Digitalmars-d-learn

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':


   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.


Re: Remove instance from array

2017-07-05 Thread Igor Shirkalin via Digitalmars-d-learn

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, 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).


Re: Remove instance from array

2017-07-05 Thread Jolly James via Digitalmars-d-learn

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, 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.


Re: Remove instance from array

2017-07-05 Thread Igor Shirkalin via Digitalmars-d-learn

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;


Re: Remove instance from array

2017-07-05 Thread Jolly James via Digitalmars-d-learn

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'.


Re: Remove instance from array

2017-07-05 Thread Igor Shirkalin via Digitalmars-d-learn

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'.


Re: Remove instance from array

2017-07-05 Thread Andrea Fontana via Digitalmars-d-learn

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

?


Remove instance from array

2017-07-05 Thread Jolly James via Digitalmars-d-learn

WhatEver[] q = [];

[...]

auto i = new WhatEver();
q[] = i;



How does one remove that instance 'i'?