readf anyone?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Jun 22 05:50:29 PDT 2010


On 06/22/2010 07:20 AM, Tyro[a.c.edwards] wrote:
> So I'm digging in and enjoying the read (and let me tell you it's a
> pretty interesting read), then I flip to page 22 (I read slow) and
> stumbled onto this code:
>
> for (double x; readf(" % ",&x) == 1; ) {
>     [snip]
> }
>
> Wait that don't look right. I don't remember readf() being
> implemented. So I decided to check things out. I jimmied up this
> little rig:
>
> void main() {
> 	double q;
> 	readf("%s",&q);
> 	writeln(q);
> }
>
> and launched it:
>
> D:\code>dmd input
> input.d(5): Error: undefined identifier readf, did you mean function
> readln?
>
> well that didn't work. Maybe I'm missing something. Let me take a
> look an the phobos doc: no, no mention there. Oh, I got it, I don't
> have the latest compiler (how stupid of me). Downloading...
> Installing... recompiling. Damn, that wasn't it. Ok, let me take a
> look at std.stdio.d. There it is, it's a member function of class
> File. Ok, I should be able to access it through stdin. Let me try
> that instead:
>
> void main() {
> 	double q;
> 	stdin.readf("%s",&q);
> 	writeln(q);
> }
>
> Here goes nothing:
>
> D:\code>dmd read
> d:\dmd2\windows\bin\..\..\src\phobos\std\format.d(2948): Error: no
> property 'len
> gth' for type 'InputByChar'
>
> Damn, that didn't work either. Now that's crazy, why would we use
> this function in the book and not take the extra effort to ensure
> that it's actually implemented before going to print? Was this an
> oversight? If so, can we please get the fix.

Sorry! I've had the message "TODO: implement readf" for a good while 
emitted during Phobos builds. You read too fast :o). I'll implement it 
today. I actually have the code somewhere already. Apologies.

Andrei


More information about the Digitalmars-d mailing list