www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Regarding isSorted

reply "bearophile" <bearophileHUGS lycos.com> writes:
This used to print true-false, now prints true-true. Is this a 
bug?


import std.stdio, std.algorithm;
void main() {
     auto x = "abcd";
     writeln(isSorted(x));
     auto y = "acbd";
     writeln(isSorted(y));
}


Maybe this line:

https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L9237

         for (; !ahead.empty; ahead.popFront(), ++i)

Should be:

         for (; !ahead.empty; ahead.popFront(), r.popFront(), ++i)

Bye,
bearophile
Feb 05 2013
next sibling parent reply Jonathan M Davis <jmdavisProg gmx.com> writes:
On Wednesday, February 06, 2013 01:33:29 bearophile wrote:
 This used to print true-false, now prints true-true. Is this a
 bug?
 
 
 import std.stdio, std.algorithm;
 void main() {
      auto x = "abcd";
      writeln(isSorted(x));
      auto y = "acbd";
      writeln(isSorted(y));
 }
 
 
 Maybe this line:
 
 https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d
 #L9237
 
          for (; !ahead.empty; ahead.popFront(), ++i)
 
 Should be:
 
          for (; !ahead.empty; ahead.popFront(), r.popFront(), ++i)
That definitely looks like a bug. "acbd" _isn't_ sorted. - Jonathan M Davis
Feb 05 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
Jonathan M Davis:

 That definitely looks like a bug. "acbd" _isn't_ sorted.
OK. Thank you. http://d.puremagic.com/issues/show_bug.cgi?id=9457 -------------------- Brad Anderson:
 Have a GitHub account, bearophile?
Not yet, but probably I will have one.
 Just hit Edit at the top of
 that link you gave, make the change, and click "Proposal File
 Change" and it'll roll up a pull request. Should take less than 
 a
 minute. I use this for almost every minor pull requests I do. 
 The
 autotester takes care of the rest.
Sounds quick & easy. I will remember this. Thank you.
 Looks like line 9221 is essentially the same code so you may 
 want
 to change that line too.
Added in the bug report. Bye, bearophile
Feb 05 2013
prev sibling next sibling parent reply Brad Anderson <eco gnuk.net> writes:
Have a GitHub account, bearophile? Just hit Edit at the top of
that link you gave, make the change, and click "Proposal File
Change" and it'll roll up a pull request. Should take less than a
minute. I use this for almost every minor pull requests I do. The
autotester takes care of the rest.

Looks like line 9221 is essentially the same code so you may want
to change that line too.

BA


On Tue, Feb 5, 2013 at 5:33 PM, bearophile <bearophileHUGS lycos.com> wrote:

 This used to print true-false, now prints true-true. Is this a bug?


 import std.stdio, std.algorithm;
 void main() {
     auto x = "abcd";
     writeln(isSorted(x));
     auto y = "acbd";
     writeln(isSorted(y));
 }


 Maybe this line:

 https://github.com/D-**Programming-Language/phobos/**
https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L9237>

         for (; !ahead.empty; ahead.popFront(), ++i)

 Should be:

         for (; !ahead.empty; ahead.popFront(), r.popFront(), ++i)

 Bye,
 bearophile
Feb 05 2013
parent "bearophile" <bearophileHUGS lycos.com> writes:
Brad Anderson:

 Just hit Edit at the top of
 that link you gave, make the change, and click "Proposal File
 Change" and it'll roll up a pull request. Should take less than 
 a minute.
Plus naturally 15-30 minutes to write down the missing unittests, that weren't written, so they didn't catch a so basic case as isSorted(string).
 The autotester takes care of the rest.
The autotester is not enough. You also need some of your brain. Bye, bearophile
Feb 06 2013
prev sibling parent Jos van Uden <usenet fwend.com> writes:
On 6-2-2013 1:33, bearophile wrote:

 Maybe this line:

 https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d#L9237

          for (; !ahead.empty; ahead.popFront(), ++i)

 Should be:

          for (; !ahead.empty; ahead.popFront(), r.popFront(), ++i)
Thought that line looked fishy. But I don't understand half the code in Phobos so I figured it must be me...
Feb 05 2013