digitalmars.D - readf anyone?
- Tyro[a.c.edwards] (39/39) Jun 22 2010 So I'm digging in and enjoying the read (and let me tell you it's a
- Andrei Alexandrescu (5/44) Jun 22 2010 Sorry! I've had the message "TODO: implement readf" for a good while
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/9) Jun 22 2010 Will that work with any type like format does? There are unformat and
- =?iso-8859-2?B?VG9tZWsgU293afFza2k=?= (1/3) Jun 22 2010 Why it takes a pointer, not a ref?
- Steven Schveighoffer (4/7) Jun 22 2010 Probably because it's variadic, so the compiler will pass by value if yo...
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.
Jun 22 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
Jun 22 2010
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
Jun 22 2010
double q;
readf("%s", &q);
Why it takes a pointer, not a ref?
Jun 22 2010
On Tue, 22 Jun 2010 16:42:46 -0400, Tomek SowiĆski <just ask.me> wrote:Probably because it's variadic, so the compiler will pass by value if you don't use a pointer. -Stevedouble q; readf("%s", &q);Why it takes a pointer, not a ref?
Jun 22 2010









=?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> 