[Issue 16724] RandomCover.popFront is a no-op for the first call

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Feb 10 16:54:05 PST 2017


https://issues.dlang.org/show_bug.cgi?id=16724

Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |joseph.wakeling at webdrake.ne
                   |                            |t

--- Comment #5 from Joseph Rushton Wakeling <joseph.wakeling at webdrake.net> ---
Sorry to have missed this, but the fix is itself broken, because it strips out
the lazy `front` of `randomCover`.

First, random algorithms (like random cover) ideally need to have a truly lazy
initial `front` value, otherwise you can run into trivial errors like:

   auto arr = [1, 2, 3, 4, 5];
   auto cover = arr.randomCover;
   cover.writeln;  // three 'different' covers
   cover.writeln;  // but each of them with
   cover.writeln;  // the same first value

... so the check on already-chosen elements in `front` wasn't there by accident
(although it may have needed further work in how it was implemented).

Second, I just tried running the above right now and got a never-ending stream
of `5, 5, 5, 5, 5, ...` out of my computer before I killed it.  So I'm not sure
that this new randomCover is working right at all :-(

--


More information about the Digitalmars-d-bugs mailing list