From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id D798DBB81 for ; Tue, 14 Dec 2004 21:35:09 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBEKZ9rL005530 for ; Tue, 14 Dec 2004 21:35:09 +0100 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 VAA05622 for ; Tue, 14 Dec 2004 21:35:08 +0100 (MET) From: romildo@uber.com.br Received: from gentoo.malaquias.no-ip.org (233-139-232.xdsl-dinamico.ctbcnetsuper.com.br [200.233.139.232]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id iBEKZ6AD005523 for ; Tue, 14 Dec 2004 21:35:08 +0100 Received: by gentoo.malaquias.no-ip.org (Postfix, from userid 500) id C0248193CA; Tue, 14 Dec 2004 18:39:30 -0200 (BRST) Date: Tue, 14 Dec 2004 18:39:30 -0200 To: Lars Nilsson Cc: caml-list@inria.fr Subject: Re: [Caml-list] Simple clock Message-ID: <20041214203930.GA26559@gentoo.malaquias.no-ip.org> Mail-Followup-To: Lars Nilsson , caml-list@inria.fr References: <20041214171716.GA10373@gentoo.malaquias.no-ip.org> <4d029f7e04121410172361f47a@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Nq2Wo0NMKNjxTN9z" Content-Disposition: inline In-Reply-To: <4d029f7e04121410172361f47a@mail.gmail.com> User-Agent: Mutt/1.5.6i X-Miltered: at concorde with ID 41BF4E7D.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 41BF4E7B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; romildo:01 caml-list:01 nilsson:01 wrote:01 wrote:01 ocaml:01 romildo:01 ocamlopt:01 cmxa:01 char:01 char:01 unix:01 unix:01 compile:01 int:01 X-Attachments: name="simple-clock.ml" X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.2 required=5.0 tests=FORGED_RCVD_HELO,NO_REAL_NAME autolearn=disabled version=3.0.0 X-Spam-Level: --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Dec 14, 2004 at 01:17:01PM -0500, Lars Nilsson wrote: > On Tue, 14 Dec 2004 17:38:50 +0000, Keith Wansbrough > wrote: > > Thread.delay > > Unix.time > > Unix.localtime > > Or Unix.select instead of Thread.delay, for that tried-and-true > solution that will give you sub-second sleep capability. > > ignore(Unix.select [] [] [] 0.5) Here is my simple clock in Ocaml. Have I done it right? Any comments? Particularly, the while, print_tm and print_newline execution time is not counted. Would that introduce an accurace in my clock? If so, is that inevitable? Romildo --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="simple-clock.ml" (* 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 *) open Unix 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 () = while true do print_tm (Unix.localtime (Unix.time ())); print_newline (); ignore (Unix.select [] [] [] 1.0) done let _ = simple_clock () --Nq2Wo0NMKNjxTN9z--