October 18, 2005
On Wed, 12 Oct 2005 15:46:43 +0200, Fredrik Olsson <peylow@gmail.com> wrote:

> At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund have a a stdio with readf functions. Is there a reason that these are not present in the official Phobos?
>
> And what is the preferred way to read stuff from the keyboard? Writef/writefln is a superb mix of the powers of Pascal's write and writeln combined with C's printf. There should be an equally powerful way to read data, should there not?

One more question.

What are the functions to read int and to know if dumb user didn't entered garbages? I would like an exception, but flag would be sufficient too.
-- 
Dawid Ciężarkiewicz
October 18, 2005
Dawid Ciężarkiewicz wrote:
> On Wed, 12 Oct 2005 15:46:43 +0200, Fredrik Olsson <peylow@gmail.com>  wrote:
> 
>> At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund  have a a stdio with readf functions. Is there a reason that these are  not present in the official Phobos?
>>
>> And what is the preferred way to read stuff from the keyboard?  Writef/writefln is a superb mix of the powers of Pascal's write and  writeln combined with C's printf. There should be an equally powerful  way to read data, should there not?
> 
> 
> One more question.
> 
> What are the functions to read int and to know if dumb user didn't entered  garbages? I would like an exception, but flag would be sufficient too.

I recommend modern programming with exceptions:

import std.conv, std.stdio;

void main() {
char[] s = "123";
int i;

try {
  i = toInt(s);
}
catch (ConvError e) {
  writefln("Bad input!");
}
catch (ConvOverflowError e) {
  writefln("Overflow!");
}

writefln("Got %d.", i);
}
October 21, 2005
On Wed, 19 Oct 2005 01:10:51 +0200, Jari-Matti Mäkelä <jmjmak@invalid_utu.fi> wrote:
>>  What are the functions to read int and to know if dumb user didn't entered  garbages? I would like an exception, but flag would be sufficient too.
>
> I recommend modern programming with exceptions:
>
> import std.conv, std.stdio;
>
> void main() {
> char[] s = "123";
> int i;
>
> try {
>    i = toInt(s);
> }
> catch (ConvError e) {
>    writefln("Bad input!");
> }
> catch (ConvOverflowError e) {
>    writefln("Overflow!");
> }
>
> writefln("Got %d.", i);
> }

Emm ... where is any form of "read" "scan" or something actually? I'm looking for standard functions (to read for example int) that throw Exceptions on mistyped input. I know how to use Exceptions. <g> ;-) (You probably misunderstood me. || I haven't make myself clear.)

Regards,
-- 
Dawid Ciężarkiewicz
November 08, 2005
Sean Kelly wrote:

>>At http://www.algonet.se/~afb/d/stdio/ in stdio.d, Anders F Björklund have a a stdio with readf functions. Is there a reason that these are not present in the official Phobos?
> 
> When I originally wrote readf I held off on submitting it because TypeInfo for
> pointers was basically broken.  As a result, my code contained a workaround to
> determine the parameter types, and I didn't feel comfortable submitting a work
> in progress (readf also relies on changed to std.utf so data can be translated
> as it is read, so the submission would requiring changing that module as well).
> Anders later patched my readf to work on GDC (if I remember correctly) and it's
> been in that state ever since. 

I'm pretty happy with how the *syntax* turned out, but not the implementation - mostly due to the aforementioned TypeInfo bugs.

Since it's using pointers (yes!, by design) it needs typeid for
that to return sane results and it didn't so I just hacked it...

Passing "mangle" characters around, and who knows what else :-P

> Personally, I would like to see readf added to
> Phobos, but as I'm not using Phobos anyway, I haven't pushed for it.  Also, as
> Ben Hinkle has mentioned, the stream classes offer a reasonable alternative for
> formatted input.  I'm fairly certain the readf/scanf functionality isn't as
> complete as the version I wrote (mine is fully C99 compliant while the
> std.stream version was an abbreviated implementation way back when I last
> checked), but it should do for most purposes.  And Mango is obviously another
> option.

I think most people turned to the various "stream" classes instead...
Or just the std.c.stdio, with printf and scanf instead of std.stdio.

Might take another look at it, like right after "D 1.0" is released :-)
Meanwhile, Sir Writef is fighting all the windmills to find Ms Readf...

> For what it's worth, my original implementation of readf is available here as
> "stdio addon":
> 
> http://www.home.f4.ca/sean/d/

Thanks, I should have linked to that in a README or something ?

I do believe I did so in the original posting to the newsgroup:
http://www.digitalmars.com/d/archives/digitalmars/D/21692.html

--anders
November 08, 2005
Anders F Björklund wrote:
> 
> I'm pretty happy with how the *syntax* turned out, but not the implementation - mostly due to the aforementioned TypeInfo bugs.
> 
> Since it's using pointers (yes!, by design) it needs typeid for
> that to return sane results and it didn't so I just hacked it...

Yeah you pretty much have to use pointers, as varargs don't allow you to specify 'out' parameters :)  But with the type safety in D, the user would have to work pretty hard to screw something up anyway.

> Might take another look at it, like right after "D 1.0" is released :-)
> Meanwhile, Sir Writef is fighting all the windmills to find Ms Readf...

It would be nice, but I'm devoting most of my nonexistent free time to Ares.  I'm not planning to look at readf any time soon either.
> 
>> For what it's worth, my original implementation of readf is available here as
>> "stdio addon":
>>
>> http://www.home.f4.ca/sean/d/
> 
> 
> Thanks, I should have linked to that in a README or something ?
> 
> I do believe I did so in the original posting to the newsgroup:
> http://www.digitalmars.com/d/archives/digitalmars/D/21692.html

I think you did.


Sean
1 2
Next ›   Last »