February 09, 2017
Hi,

I was trying to run the example code from

	https://dlang.org/phobos/std_stdio.html#.File.lockingBinaryWriter

which is very short, as follows.

===

import std.algorithm, std.range, std.stdio;
void main()
{
    enum size = 500;
    writef("P5\n%d %d %d\n", size, size, ubyte.max);

    iota(-1, 3, 2.0/size).map!(y =>
        iota(-1.5, 0.5, 2.0/size).map!(x =>
            cast(ubyte)(1+
                recurrence!((a, n) => x + y*1i + a[n-1]^^2)(0+0i)
                .take(ubyte.max)
                .countUntil!(z => z.re^^2 + z.im^^2 > 4))
        )
    )
    .copy(stdout.lockingBinaryWriter);
}

===

Unfortunately, my compiler fails with

> $ gdc -Wall -o m1 m1.d m2.d:14:17: error: no property 'lockingBinaryWriter' for type 'File'
>      .copy(stdout.lockingBinaryWriter);

It looks like the latest in the repository isn't recent enough, since the source code online to stdio.d on github has lockingBinaryWriter in it, but my copy installed via ubuntu apt does not.

I tried

> $ gdc --version

and got

> gdc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005

but that doesn't say what version the frontend compiler or standard library is.  After searching on the web, I found a pragma that I added to the file

> pragma(msg, __VERSION__);

which gave the version "2068L" when I compiled it. According to

	https://gdcproject.org/downloads

the latest gdc(1) uses the DMDFE version 2.068.2 which isn't new enough I guess, since the DMD version appears to be 2.073.0 which includes lockingBinaryWriter.

This fixes the problem:

===

import std.range, std.array, std.stdio;

void main()
{
    auto buf = appender!(ubyte[])();
    enum size = 500;
    writef("P5\n%d %d %d\n", size, size, ubyte.max);
    iota(-1, 3, 2.0/size).map!(y =>
        iota(-1.5, 0.5, 2.0/size).map!(x =>
            cast(ubyte)(1+
                recurrence!((a, n) => x + y*1i + a[n-1]^^2)(0+0i)
                .take(ubyte.max)
                .countUntil!(z => z.re^^2 + z.im^^2 > 4))
        )
    )
    .copy(buf);
    stdout.rawWrite(buf.data);
}

===

And running it

> $ gdc -Wall -o m2 m2.d && ./m1 > aaa.pnm && display aaa.pnm

produces the expected result.

I'm posting this in case anyone else encounters this problem.  I don't know D at all, and perhaps this will save someone else from some head scratching and going down output iterator rabbit holes.

Best regards,

Oasiq.