Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] kprintf with user formatters
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus@o...>
Subject: Re: [Caml-list] kprintf with user formatters
On Fri, 16 Jul 2004, Pierre Weis wrote:
> I don't know of any way to safely prevent the arguments of printf from
> being converted to string when interpreting the format.

This would probably require some changes in the implementation of

> Since you have a if then else, the ``???'' expression should have
> exactly the same type as the ``then kfprintf ...'' expression. Hence
> the simplest way to do so is to have another kfprintf invocation with
> the same format. Evidently you want to redirect the output of this
> invocation to /dev/null (I mean you do not want to see its output).

Not only this: I want to prevent any computations associated with
generating output strings.

> The best way to do so is not to redefine a specialized version of
> printf, it is simply to define a specialized pretty printer that would
> behave as you want and then to specialize fprintf with it:
> let null_formatter =
>   let null_out s idx len = () in
>   let null_flush = ignore in
>   Format.make_formatter null_out null_flush;;

This would surely ignore any output, but "null_out" would still be called
with superfluously generated strings.

Anyway, the argument-eating function that makes use of "Obj.magic"
works for me so my problem is solved.


Markus Mottl

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: