From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id GAA09438; Sat, 27 Apr 2002 06:43:56 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id GAA09528 for ; Sat, 27 Apr 2002 06:43:54 +0200 (MET DST) Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.25.148.40]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3R4hqT15974 for ; Sat, 27 Apr 2002 06:43:53 +0200 (MET DST) Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id g3R4hVXt026298; Sat, 27 Apr 2002 14:43:31 +1000 (EST) Received: from ozemail.com.au (ppp7.dyn146.pacific.net.au [210.23.146.7]) by wisma.pacific.net.au with ESMTP id OAA05582; Sat, 27 Apr 2002 14:43:26 +1000 (EST) Message-ID: <3CCA2C6E.5020007@ozemail.com.au> Date: Sat, 27 Apr 2002 14:43:26 +1000 From: John Max Skaller User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: Chris Hecker CC: Tomasz Zielonka , caml-list@inria.fr Subject: Re: pervasives (was: Re: [Caml-list] How to read three integers from a text-file... ?) References: <4.3.2.7.2.20020424222749.02d10a90@mail.d6.com> <15557.14957.358556.545541@absurd.mimuw.edu.pl> <15557.14957.358556.545541@absurd.mimuw.edu.pl> <4.3.2.7.2.20020424222749.02d10a90@mail.d6.com> <4.3.2.7.2.20020425104214.02e42a90@mail.d6.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 in-core. 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, mailto:skaller@ozemail.com.au snail:10/1 Toxteth Rd, Glebe, NSW 2037, Australia. voice:61-2-9660-0850 ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners