| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
June 22, 2010 readf anyone? | ||||
|---|---|---|---|---|
| ||||
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.
| ||||
June 22, 2010 Re: readf anyone? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Tyro[a.c.edwards] | 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
| |||
June 22, 2010 Re: readf anyone? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Andrei Alexandrescu wrote:
> 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.
Will that work with any type like format does? There are unformat and formattedRead in format.d. Is FormatInfo a user serviceable part? :)
Could you please show an example on how to unformat any type.
It may already be in the book but I haven't gotten to that point yet. :)
Ali
| |||
June 22, 2010 Re: readf anyone? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Tyro[a.c.edwards] | > double q;
> readf("%s", &q);
Why it takes a pointer, not a ref?
| |||
June 22, 2010 Re: readf anyone? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Tomek Sowiński | On Tue, 22 Jun 2010 16:42:46 -0400, Tomek Sowiński <just@ask.me> wrote:
>> double q;
>> readf("%s", &q);
>
> Why it takes a pointer, not a ref?
Probably because it's variadic, so the compiler will pass by value if you don't use a pointer.
-Steve
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply