From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA04905; Tue, 12 Jun 2001 17:12:47 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 RAA05033 for ; Tue, 12 Jun 2001 17:12:47 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f5CFCfj20596; Tue, 12 Jun 2001 17:12:41 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA05131; Tue, 12 Jun 2001 17:12:40 +0200 (MET DST) From: Pierre Weis Message-Id: <200106121512.RAA05131@pauillac.inria.fr> Subject: Re: [Caml-list] Evaluation Order In-Reply-To: <3B2384BE.5587F31F@ozemail.com.au> from John Max Skaller at "Jun 11, 101 00:31:26 am" To: skaller@ozemail.com.au (John Max Skaller) Date: Tue, 12 Jun 2001 17:12:40 +0200 (MET DST) Cc: tl001@online.no, caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Tore Lund wrote: > > > # let _ = > > print_string "before"; > > print_string "MIDDLE"; > > print_string "after";; > > beforeMIDDLEafter- : unit = () > > > > but not in this one: > > > > # let _ = > > print_string "before"; > > Format.print_string "MIDDLE"; > > print_string "after";; > > beforeafterMIDDLE- : unit = () > > > > What's going on here? > > Buffering I guess. print_string buffers using stdio buffers. > Format.* has its own buffer, which is flushed into the > stdout buffer too late. > > > -- > John (Max) Skaller, mailto:skaller@maxtal.com.au > 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 > checkout Vyper http://Vyper.sourceforge.net > download Interscript http://Interscript.sourceforge.net > ------------------- > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Thank you for pointing out this delicate point. I added your example and some basic explanation to the FAQ: ----------------------------------------------------------------------

Why some printing material is mixed up and does not appear in the right order ?

If you use printing functions of the format module, you might not mix printing commands from format with printing commands from the basic I/O system. In effect, the material printed by functions from the format module is delayed (stored into the pretty-printing queue) in order to find out the proper line breaking to perform with the material at hand. By contrast low level output is performed with no more buffering than usual I/O buffering. So that you can observe the following output differences between pure low level output:

# print_string "before";
  print_string "MIDDLE";
  print_string "after";;
beforeMIDDLEafter- : unit = ()
and mixed calls to low and high level printing:
# print_string "before";
  Format.print_string "MIDDLE";
  print_string "after";;
beforeafterMIDDLE- : unit = ()

To avoid this kind of problems you should not mix printing orders from format and basic printing commands; that's the reason why when using functions from the format module, it is considered good programming habit to open format globally in order to completely mask low level printing functions by the high level printing functions provided by format.

N.B: format printings are automatically flushed after each evaluation in the interective system. Explicit flushes are also performed by calling the print_newline function that emits a line break and empties the pretty printer queue. ---------------------------------------------------------------------- All constructive criticisms are warmly welcome. Best regards, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr