English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Format question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-11-20 (00:27)
From: David Frese <dfrese@d...>
Subject: Re: [Caml-list] Format question
On Wed, 2002-11-06 at 23:49, Oleg wrote:
> Hi
> Is it possible to define a printf that automatically flushes stdout?
> let my_printf x = Printf.printf x; flush stdout;;
> my_printf "%i" 3;;
> doesn't work (Incorrect number of arguments, as the type of my_printf is 
> different from Printf.printf)


I read your message a little late, but this seems to work:

let flprintf ch fmt =
  let rec test x =
    if (Obj.magic x) = ()
    then begin flush ch; Obj.magic () end
    else Obj.magic (fun next -> test ((Obj.magic x) next))
    test (Printf.fprintf ch fmt)

let my_printf = flprintf stdout

As far as I know, no function will ever be represented as 0, which is
the internal representation of (). The code depends on that fact...


To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners