Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 04, 2010 std.algorithm.sort fails? | ||||
---|---|---|---|---|
| ||||
Hi, I'm trying to sort an array of strings exactly the way it's done in the docs, but I don't get the expected results:
----------------------------
import std.algorithm;
import std.stdio;
import std.contracts;
void main()
{
string[] arr = ["unions", "vars", "d_enum", "constructors",
"d_alias", "all", "templates", "classes",
"interfaces", "sections", "structs", "nested",
"functions"];
sort!("toupper(a) < toupper(b)", SwapStrategy.stable)(arr);
foreach(string a; arr)
{
writeln(a);
}
enforce(arr != ["all", "classes", "functions", "constructors",
"d_alias", "d_enum", "interfaces", "nested",
"sections", "structs", "templates", "unions",
"vars"]);
}
-----------------------------
The enforcement fails. Can anyone reproduce this or is this even a known bug?
--
Johannes Pfau
|
August 04, 2010 Re: std.algorithm.sort fails? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Pfau | On Wednesday 04 August 2010 02:17:31 Johannes Pfau wrote:
> Hi, I'm trying to sort an array of strings exactly the way it's done in the docs, but I don't get the expected results:
>
> ----------------------------
> import std.algorithm;
> import std.stdio;
> import std.contracts;
>
> void main()
> {
> string[] arr = ["unions", "vars", "d_enum", "constructors",
> "d_alias", "all", "templates", "classes",
> "interfaces", "sections", "structs", "nested",
> "functions"];
>
> sort!("toupper(a) < toupper(b)", SwapStrategy.stable)(arr);
>
> foreach(string a; arr)
> {
> writeln(a);
> }
>
> enforce(arr != ["all", "classes", "functions", "constructors",
> "d_alias", "d_enum", "interfaces", "nested",
> "sections", "structs", "templates", "unions",
> "vars"]);
> }
> -----------------------------
>
> The enforcement fails. Can anyone reproduce this or is this even a known bug?
There appears to be a bug with regards to SwapStrategy.stable. If you don't pass it a swap strategy it works just fine, but if you do, it fails.
I'm using svn snapshot 1751 of phobos, which is a few weeks old, and it fails an assertion in sort() which is checking whether the range was sorted. I have no idea if it's been fixed since then. I don't see a bug report for it in either case.
- Jonathan M Davis
|
August 05, 2010 Re: std.algorithm.sort fails? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 04.08.2010 11:34, Jonathan M Davis wrote: > > There appears to be a bug with regards to SwapStrategy.stable. If you don't pass it a swap strategy it works just fine, but if you do, it fails. > > I'm using svn snapshot 1751 of phobos, which is a few weeks old, and it fails an assertion in sort() which is checking whether the range was sorted. I have no idea if it's been fixed since then. I don't see a bug report for it in either case. > > - Jonathan M Davis Ok, I'll just use it without SwapStrategy.stable then. I guess I could also test the phobos svn version at some time and if the assert still fails the phobos devs likely already now that. -- Johannes Pfau |
August 05, 2010 Re: std.algorithm.sort fails? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Pfau | On Thursday 05 August 2010 01:26:32 Johannes Pfau wrote:
> On 04.08.2010 11:34, Jonathan M Davis wrote:
> > There appears to be a bug with regards to SwapStrategy.stable. If you don't pass it a swap strategy it works just fine, but if you do, it fails.
> >
> > I'm using svn snapshot 1751 of phobos, which is a few weeks old, and it fails an assertion in sort() which is checking whether the range was sorted. I have no idea if it's been fixed since then. I don't see a bug report for it in either case.
> >
> > - Jonathan M Davis
>
> Ok, I'll just use it without SwapStrategy.stable then. I guess I could also test the phobos svn version at some time and if the assert still fails the phobos devs likely already now that.
You'd probably be better off creating a bug report. The phobos devs don't catch everything and neither do their unit tests. And even if they're aware of it, a bug report will serve as a reminder to them so that they don't forget. I know that Andrei has asked people to create bug reports on a few occasions when he was already aware of a issue that they pointed out, because he didn't want to forget it.
- Jonathan M Davis
|
August 05, 2010 Re: std.algorithm.sort fails? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 05.08.2010 11:28, Jonathan M Davis wrote: > On Thursday 05 August 2010 01:26:32 Johannes Pfau wrote: >> On 04.08.2010 11:34, Jonathan M Davis wrote: >>> There appears to be a bug with regards to SwapStrategy.stable. If you don't pass it a swap strategy it works just fine, but if you do, it fails. >>> >>> I'm using svn snapshot 1751 of phobos, which is a few weeks old, and it fails an assertion in sort() which is checking whether the range was sorted. I have no idea if it's been fixed since then. I don't see a bug report for it in either case. >>> >>> - Jonathan M Davis >> >> Ok, I'll just use it without SwapStrategy.stable then. I guess I could also test the phobos svn version at some time and if the assert still fails the phobos devs likely already now that. > > You'd probably be better off creating a bug report. The phobos devs don't catch everything and neither do their unit tests. And even if they're aware of it, a bug report will serve as a reminder to them so that they don't forget. I know that Andrei has asked people to create bug reports on a few occasions when he was already aware of a issue that they pointed out, because he didn't want to forget it. > > - Jonathan M Davis OK I reported it, thanks for your help. http://d.puremagic.com/issues/show_bug.cgi?id=4584 Btw: it also asserts in phobos for me. I just never saw the assert because my distributions package now has -release in the default dmd.conf and -debug on the command line doesn't seem to override -release in dmd... -- Johannes Pfau |
August 05, 2010 Re: std.algorithm.sort fails? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Johannes Pfau | On Thursday 05 August 2010 03:23:54 Johannes Pfau wrote:
> OK I reported it, thanks for your help. http://d.puremagic.com/issues/show_bug.cgi?id=4584
>
> Btw: it also asserts in phobos for me. I just never saw the assert because my distributions package now has -release in the default dmd.conf and -debug on the command line doesn't seem to override -release in dmd...
-release and -debug actually have nothing to do with each other. -release tells dmd to compile in release mode, which means that it removes various checks likes assertions (though I think that some checks like array bounds checking is still left in for safe modules). -debug enables debugging statements. e.g.
debug
{
//only compiled in with -debug enabled
}
You can actually have both -release and -debug at the same time, so it's a bit confusing. But -release has to do with release/debug mode whille -debug has to do with enabling debug statements. They're totally unrelated.
- Jonathan M Davis
|
Copyright © 1999-2021 by the D Language Foundation