Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* print and output
@ 1997-07-01  9:43 Michel Levy
  1997-07-02 18:43 ` Adam P. Jenkins
  1997-07-03  7:54 ` Pierre Weis
  0 siblings, 2 replies; 3+ messages in thread
From: Michel Levy @ 1997-07-01  9:43 UTC (permalink / raw)
  To: caml-list

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







^ permalink raw reply	[flat|nested] 3+ messages in thread

* print and output
  1997-07-01  9:43 print and output Michel Levy
@ 1997-07-02 18:43 ` Adam P. Jenkins
  1997-07-03  7:54 ` Pierre Weis
  1 sibling, 0 replies; 3+ messages in thread
From: Adam P. Jenkins @ 1997-07-02 18:43 UTC (permalink / raw)
  To: caml-list

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: print and output
  1997-07-01  9:43 print and output Michel Levy
  1997-07-02 18:43 ` Adam P. Jenkins
@ 1997-07-03  7:54 ` Pierre Weis
  1 sibling, 0 replies; 3+ messages in thread
From: Pierre Weis @ 1997-07-03  7:54 UTC (permalink / raw)
  To: Michel Levy; +Cc: caml-list

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

J'ai essaye' vos diffe'rentes versions, et toutes marchaient comme
vous vous y attendez. Je pense que votre proble`me vient peut-e^tre du
fait que vous utilisez la bibliothe`que Format. En ce cas, il y a un
retard a` l'impression car il faut attendre le mate'riel d'impression
pour pouvoir imprimer correctement. Si vous avez effectivement fait
open Format, il vous faut vider la queue d'impression avec
print_flush. E'crivez:

         print_string ">>"; print_flush (); read_int ();;

Ou bien appelez directement la primitive de base:

         Pervasives.print_string ">>"; read_int ();;

> Hi
> 
> When I write (in OCAML) the following program :
>         print_string ">>"; read_int ();;
> the reading takes place before the printing, what surprises me.

I tried your programs and they work fine, as you expect them to
work. My guess is that you don't use the basic print_string function,
but the one of the Format library module. That may be the case if you
have already open the Format module. In that case, you need to
flush the formatting queue with print_flush. You may write

         print_string ">>"; print_flush (); read_int ();;

Alternatively, you may directly call the standard primitive with:

         Pervasives.print_string ">>"; read_int ();;

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/







^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-07-03  7:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-01  9:43 print and output Michel Levy
1997-07-02 18:43 ` Adam P. Jenkins
1997-07-03  7:54 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox