Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] How to read three integers from a text-file... ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Max Skaller <skaller@o...>
Subject: Re: pervasives (was: Re: [Caml-list] How to read three integers from a text-file... ?)
Chris Hecker wrote:

>> This function assumes that every integer is on a separate line. This is
>> rarely true in programming contests.
> Ah, I missed the "read one line" part.  Interesting that print_int 
> doesn't insert a newline but read_int eats one...another assymetry.  
> int_of_string also seems to require that the string be only the 
> integer, so int_of_string "123 some more" excepts.
> It seems like it might be useful to have the core simple types 
> (string, int, float) have orthogonal reading and writing functions in 
> Pervasives.  Maybe it's not worth the effort, though... 

I have a philosophy .. a bit extreme perhaps .. I NEVER read anything
other than lines (or whole files). Always parse in-core. So the 'asymmetry'
doesn't worry me .. the existence of useless functions does though.
I'd get rid of all input other than read line/read file. Similarly,
though I'm slightly less pedantic here .. output should be formatted 
So you only need one output function (print string).
I'd get rid of all the others .. and also get rid of printf ..

I can only site an example .. an academic compiler that printed
terms out  .. I had to rewrite reams of code
to generate strings when I needed to reroute the output ..
there was also a need to generate 'potential' output ..
diagnostic information that needed to be gleaned
to print an error message .. before it was known
if there was actually an error.

In-core formatting/parsing is sometimes slower
than doing the same job on output/input,
and may use more memory .. but the contexts where this is important are
fairly rare.

John Max Skaller,
snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia.

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: