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 UAA15600; Wed, 10 Jul 2002 20:50:17 +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 UAA15596 for ; Wed, 10 Jul 2002 20:50:16 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from athlon.baretta.com (r-mi214-6a41.tin.it [62.211.4.41]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g6AIoEb13346 for ; Wed, 10 Jul 2002 20:50:15 +0200 (MET DST) Received: from baretta.com (localhost.localdomain [127.0.0.1]) by athlon.baretta.com (Postfix) with ESMTP id 977232739C for ; Wed, 10 Jul 2002 20:56:56 +0200 (CEST) Message-ID: <3D2C8378.60604@baretta.com> Date: Wed, 10 Jul 2002 20:56:56 +0200 From: Alessandro Baretta Organization: Baretta srl -- www.baretta.com User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020529 X-Accept-Language: it, en MIME-Version: 1.0 To: Ocaml Subject: Re: [Caml-list] productivity improvement References: <200207081952.PAA28813@hickory.cc.columbia.edu> <200207082014.g68KE0n02894@orchestra.cs.caltech.edu> <3D2C57B2.4010907@ozemail.com.au> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk John Max Skaller wrote: > > As someone said recently "ocaml forever" :-)) > Just today I have found a counterexample where C does a better job than O'Caml--at least within the context of my understanding of and ability with the two languages. This is the problem: I have a text file containing a fairly long table extracted from a database (approximately 73000 lines). I had to write a program to parse each line, extract only the relevant fields and reformat dates and times according to some sensible format (such as dd/mm/yyyy hh:mm:ss as opposed to yyyymmdd hhmmss00). This is how I solved the problem in C: #include int main ( int argc , char *argv[]) { #define ALF " %*s" #define ISIN " %*s" #define DATE " %4s%2s%2s" #define TIME " %2s%2s%2s%*2s" #define PRICE "%s" #define QN "%s" #define CNTVL "%*s" char scanner[] = ALF ISIN DATE TIME PRICE QN CNTVL; char printer[] = "%s/%s/%s\t%s:%s:%s\t%s\t%s\n"; char year[8], month[8], day[8]; char hh[4], mm[4], ss[4]; char price[64], qn[64]; int n; while (1) { n=scanf(scanner, year, month, day, hh, mm, ss, price, qn); if (n==EOF) break; printf(printer, day, month, year, hh, mm, ss, price, qn); } } I was not able to figure out an easy way to do this in O'Caml. Of course, I could have used ocamllex and ocamlyacc to define a lexer and a parser, but what I really needed was a scanf function. My intuition is that we badly need a *functional* scanf. Of course, I despise the idea of a format string. I had to use 7 #defines in order to make some sense of the scanf format, and I might have done the same for printf, where the format not a little simpler. Of course, my understanding of O'Caml is incomplete, and I'm sure someone will be good enough to teach how I could have done the same in O'Caml with only a fraction of the lines of code. Alex ------------------- 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