English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: [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-19 (11:11)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] productivity improvement
> Determine Dr. Leroy's involvement in JFK assassination 180

Should take less time than this, given that I wasn't born at that time :-)

As everyone else, I'll point out that your code can be shortened and
made more readable by judicious use of printf and regexps (see below).
But really, if this is the kind of programs you're interested in
(text-based I/O with no data structures), forget about C++ and Caml,
and use Perl.

- Xavier Leroy

open Printf

let print_time m =
  let hours = (m / 60) mod 24 and minutes = m mod 60 in
  printf "%2d:%02d%s"
         (if hours > 12 then hours - 12 else hours)
         (if hours > 12 then "pm" else "am")

let print_duration m =
  let hours = (m / 60) mod 24 and minutes = m mod 60 in
  printf "%2d:%02d" hours minutes

let re = Str.regexp "\\(.*\\)[ \t]+\\([0-9]+\\)$"

let split_string s =
  if Str.string_match re s 0
  then (Str.matched_group 1 s, int_of_string (Str.matched_group 2 s))
  else failwith "bad line"
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