From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA21388 for caml-redistribution; Thu, 3 Jul 1997 09:43:58 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA18134 for ; Wed, 2 Jul 1997 20:44:16 +0200 (MET DST) Received: from dwarin.oit.umass.edu (freya.cs.umass.edu [128.119.40.195]) by nez-perce.inria.fr (8.8.5/8.7.3) with ESMTP id UAA12615 for ; Wed, 2 Jul 1997 20:44:09 +0200 (MET DST) Received: (from ajenkins@localhost) by dwarin.oit.umass.edu (8.8.5/8.8.5) id OAA00394; Wed, 2 Jul 1997 14:43:10 -0400 Date: Wed, 2 Jul 1997 14:43:10 -0400 Message-Id: <199707021843.OAA00394@dwarin.oit.umass.edu> From: "Adam P. Jenkins" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: caml-list@inria.fr Subject: print and output In-Reply-To: References: X-Mailer: VM 6.31 under Emacs 19.34.1 Sender: weis Michel Levy writes: > Bonjour, > > Quand j'ecris (en Ocaml) le "programme" suivant : > print_string ">>"; read_int ();; > l'impression a lieu apres la lecture, ce qui me surprend, car il est dit > val read_int : unit -> int > Flush standart output then ... > > Quand j'ecris le "programme" suivant : > output_string ">>"; read_int ();; > l'impression a lieu avant la lecture, ce qui est heureux. > > Pourquoi cette diffence, car je pensais que : > print_string = output_string stdout > > Hi > > When I write (in OCAML) the following program : > print_string ">>"; read_int ();; > the reading takes place before the printing, what surprises me. > > On the contrary, when I write : > output_string ">>"; read_int ();; > the printing takes place before the reading, what is better. > > Why this difference, whereas I thought that : > print_string = output_string stdout > > > Michel Levy > D106 - Laboratoire LSR > B.P.72 - 38402 SAINT MARTIN D'HERES CEDEX - France > Tel : 0476827246 > e.mail : Michel.Levy@imag.fr > > > > That is kind of strange, since print_string is implemented with output_string. Maybe it just had to do with the order in which you executed the commands, i.e. when the stdout buffer became full. > cd /usr/local/lib/ocaml > grep print_string pervasives.ml let print_string s = output_string stdout s To make the printing happen first in either case, you can add "flush stdout;". print_string ">>"; flush stdout; read_int ();; Adam