From: Kurt Welgehausen <kwel@kwel.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Simple clock
Date: Tue, 14 Dec 2004 21:20:13 -0600 [thread overview]
Message-ID: <41BFAD6D.mail1UT21XGTC@kwel.net> (raw)
In-Reply-To: <20041214203930.GA26559@gentoo.malaquias.no-ip.org>
(*** Here are a few things to investigate if you're learning ocaml *)
(*** "**" in opening comment, for ocamldoc *)
(** simple-clock.ml
Repeatedly prints the current time at the standard output,
at intervals of 1 sec
How to compile:
ocamlopt unix.cmxa simple-clock.ml -o simple-clock
*)
(*** You don't need to open the module if you qualify names with "Unix." *)
(*open Unix*)
(*** It's not important in such a simple program, but you can hide
functions like print_tm that are used only by one other function *)
(*let print_tm tm =
print_int tm.tm_hour;
print_char ':';
print_int tm.tm_min;
print_char ':';
print_int tm.tm_sec
*)
let simple_clock () =
let print_tm tm =
(*** so you don't get "7:8:9" *)
Printf.printf "%2d:%02d:%02d\n"
tm.Unix.tm_hour tm.Unix.tm_min tm.Unix.tm_sec;
flush stdout in
(*** This works, but in ocaml you can do it in a more functional style *)
(* while true do
print_tm (Unix.localtime (Unix.time ()));
print_newline ();
ignore (Unix.select [] [] [] 1.0)
done
*)
let rec loop () =
print_tm (Unix.localtime (Unix.time ()));
ignore (Unix.select [] [] [] (1. -. (fst (modf (Unix.gettimeofday ())))));
loop () in
loop () in
simple_clock ()
(*let _ = simple_clock ()*)
(*** It's easier to read if you remove my comments and the code that
I've commented out. Have fun *)
next prev parent reply other threads:[~2004-12-15 3:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-14 17:17 romildo
2004-12-14 17:38 ` [Caml-list] " Keith Wansbrough
2004-12-14 18:17 ` Lars Nilsson
2004-12-14 20:39 ` romildo
2004-12-14 21:52 ` Ville-Pertti Keinonen
2004-12-15 3:20 ` Kurt Welgehausen [this message]
2004-12-15 17:37 ` Evan Martin
2004-12-14 20:43 ` romildo
2004-12-15 3:00 ` skaller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=41BFAD6D.mail1UT21XGTC@kwel.net \
--to=kwel@kwel.net \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox