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] productivity improvement
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-07-11 (23:45)
From: Pierre Weis <pierre.weis@i...>
Subject: Re: [Caml-list] productivity improvement
> 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 Archives:
> Bug reports: FAQ:
> Beginner's list:

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:

  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)
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,,

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