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 BAA11061; Fri, 12 Jul 2002 01:45:40 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA11054 for ; Fri, 12 Jul 2002 01:45:40 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6BNiaD28691; Fri, 12 Jul 2002 01:45:01 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id BAA10954; Fri, 12 Jul 2002 01:43:16 +0200 (MET DST) From: Pierre Weis Message-Id: <200207112343.BAA10954@pauillac.inria.fr> Subject: Re: [Caml-list] productivity improvement In-Reply-To: <20020710.210902.730554487.Jun.Furuse@inria.fr> from "Jun P.FURUSE" at "Jul 10, 102 09:09:02 pm" To: Jun.Furuse@inria.fr (Jun P.FURUSE) Date: Fri, 12 Jul 2002 01:43:16 +0200 (MET DST) Cc: alex@baretta.com, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hello, > > > 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. > [..] > > 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. > > Ah, you should have waited for few days. > The module Scanf is available in the next O'Caml version 3.05, > which will be distributed soon... > > - > Jun > > ------------------- > 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 As Jun said, a scanf facility will be introduce in the next version of Objective Caml. Consider this feature as experimental, and fill free to send us comments, if you can test it, have remarks or additions to suggest, or more importantly, if you find bugs before the release! With this new (functional) scanf facility, your program sounds like this in Caml: try while true do Scanf.scanf " %s %s %4s%2s%2s %2s%2s%2s%2s %s %s %s" (fun _ _ year month day hh mm ss _ price qn _ -> Printf.printf "%s/%s/%s\t%s:%s:%s\t%s\t%s\n" day month year hh mm ss price qn) done with End_of_file -> ();; We can now compare with your C version of the program: Conciseness and elegance: well, I'm not too unhappy of the Caml code, but yes, it can be considered as a bit cryptic ... Readability: in this example, we certainly lack the ability to skip an argument as in the %*s of the C version; also, and once again, we lack a format concatenation primitive to cleanly express the decomposition of the scanf format at hand (which means that we still lack the fourth type variable argument in the type of format strings that would permit the sound implementation of this feature). Performance: compared to the ggc-O2 compiled C version, this program is about twice slowlier, which is a performance of the Objective Caml compiler, given the highly readable and simple-minded source code of the Scanf module. Anyway, thanks a lot for your interesting example that forced me to review the code of the Scanf module, and to slightly modify its functionalities in order to accomodate your program more elegantly! Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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