caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Frese <dfrese@dfrese.de>
To: Oleg <oleg_inconnu@myrealbox.com>
Cc: Caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Format question
Date: 20 Nov 2002 01:29:16 +0100	[thread overview]
Message-ID: <1037752156.2910.10.camel@localhost.localdomain> (raw)
In-Reply-To: <200211062249.RAA07810@apakabar.cc.columbia.edu>

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)

Hello,

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))
  in
    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...

David.

-------------------
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


  parent reply	other threads:[~2002-11-20  0:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-06 22:49 Oleg
2002-11-06 23:46 ` David Brown
2002-11-20  0:29 ` David Frese [this message]
2002-11-07  0:09 Oleg
2002-11-07  0:31 ` Alessandro Baretta
2002-11-07  0:46 ` Gerd Stolpmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1037752156.2910.10.camel@localhost.localdomain \
    --to=dfrese@dfrese.de \
    --cc=caml-list@inria.fr \
    --cc=oleg_inconnu@myrealbox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).