digitalmars.D.bugs - [Issue 6849] New: std.algorithm.remove design
- d-bugmail puremagic.com (58/63) Oct 25 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6849
- d-bugmail puremagic.com (11/11) Oct 25 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6849
- d-bugmail puremagic.com (8/22) Oct 26 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6849
- d-bugmail puremagic.com (8/16) Oct 26 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6849
- d-bugmail puremagic.com (8/20) Oct 26 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6849
- d-bugmail puremagic.com (9/9) Nov 15 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6849
- d-bugmail puremagic.com (9/9) Nov 15 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6849
http://d.puremagic.com/issues/show_bug.cgi?id=6849
Summary: std.algorithm.remove design
Product: D
Version: D2
Platform: x86
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody puremagic.com
ReportedBy: bearophile_hugs eml.cc
A D2 program:
import std.stdio, std.algorithm;
void main() {
dchar[] data = "abcde"d.dup;
writeln(data);
writeln(remove(data, 0));
writeln(data);
writeln(remove(data, 2));
writeln(data);
}
With DMD 2.056beta3 it prints:
abcde
bcde
bcdee
bcee
bceee
Expected output:
abcde
bcde
bcde
bce
bce
Or maybe it's better for remove() to return void, to underline its in-place
nature (this is often done in Python, where functions the modify da in-place
usually return just None, and functions with a name that ends with "ed" create
new data and return it, like the sort/sorted pair):
import std.stdio, std.algorithm;
void main() {
dchar[] data = "abcde"d.dup;
writeln(data);
data.remove(0);
writeln(data);
data.remove(2);
writeln(data);
}
Expected output:
abcde
bcde
bce
This is similar to what happens in Python2:
data = ['a', 'b', 'c', 'd', 'e']
del data[0]
data
['b', 'c', 'd', 'e']
del data[2]
data
['b', 'c', 'e']
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 25 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6849 I didn't fully understand the situation, as it often happens: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=30277 Yet I think the problem exists, and there are Python (and other languages) programmers too coming to D. See some comments, with an alternative proposal too, about a replaceInPlace() function: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=30281 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 25 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6849
From the same thread:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=30294
Steven Schveighoffer:
Here is the resulting array and final state of a:
import std.stdio, std.algorithm;
void main() {
int[] a = [ 0, 1, 2, 3 ];
writeln( remove!(SwapStrategy.unstable)(a, 1));
writeln(a);
}
output:
[3, 1, 2]
[3, 1, 2, 3]
Clearly, index 0 was removed, not index 1. Please file a bug.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6849 10:25:44 PDT ---From the same thread: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=30294 Steven Schveighoffer:This is not a design bug, it's an actual bug in the code (does not work as designed), it should be separate from this enhancement request. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------Clearly, index 0 was removed, not index 1. Please file a bug.
Oct 26 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6849Right, it's my mistake of mixing two different things in the same issue. Sorry. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------From the same thread: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=30294 Steven Schveighoffer:This is not a design bug, it's an actual bug in the code (does not work as designed), it should be separate from this enhancement request.Clearly, index 0 was removed, not index 1. Please file a bug.
Oct 26 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6849 To clear up this bug report I close it and replace it with a a bug report and a more focused enhancement request. See also bug 6957. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 15 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6849
bearophile_hugs eml.cc changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 15 2011









d-bugmail puremagic.com 