* $0.02 suggestion for the Printf module
@ 1999-10-18 16:15 Alain Frisch
1999-10-19 19:15 ` William Chesters
0 siblings, 1 reply; 2+ messages in thread
From: Alain Frisch @ 1999-10-18 16:15 UTC (permalink / raw)
To: caml-list
As I didn't find a powerful enough preprocessor, and I find perl ugly,
I try to use OCaml to generate text file (html, latex, etc ...).
So I have a global mutable variable containing a printing function.
In different situation, this function write directly to a file or add the
text to a buffer (to preprocess it before sending it), or filter the text
through another function, etc ...
I want to use the printf formating functions. With the current Printf
module, I have to use create a buffer, bprintf in the buffer, extract the
content of the buffer, print this string with my printing function.
As I want to do it often, it would be useful to have a function :
gen_printf: (string -> ()) -> ('a, Buffer.t, unit) format -> 'a
[or for performance (string -> ()) -> (char -> ()) -> ('a, ... ]
taking as its first argument a 'printing function'
(so printf == gen_printf print_string; etc ...)
As far as I know it is impossible to implement it in the core langage,
so the only solution for the moment is to hack with the source code of
Printf (it takes 20 seconds to implement gen_printf from printf).
I think it would be a good idea to add such a function in the Printf
module.
Btw, I don't understand the tests performed on the format 'string' in
Printf functions : aren't they already done by the compiler during the
typing ?
--
Alain Frisch
^ permalink raw reply [flat|nested] 2+ messages in thread
* $0.02 suggestion for the Printf module
1999-10-18 16:15 $0.02 suggestion for the Printf module Alain Frisch
@ 1999-10-19 19:15 ` William Chesters
0 siblings, 0 replies; 2+ messages in thread
From: William Chesters @ 1999-10-19 19:15 UTC (permalink / raw)
To: Alain Frisch; +Cc: caml-list
Alain Frisch writes:
> As I want to do it often, it would be useful to have a function :
>
> gen_printf: (string -> ()) -> ('a, Buffer.t, unit) format -> 'a
> [or for performance (string -> ()) -> (char -> ()) -> ('a, ... ]
>
> taking as its first argument a 'printing function'
You can do this with Format (and of course you get pretty-printing as
well)---see Format.formatter_of_out_channel, etc. I don't know what
the performance difference, if any, between Printf and Format is.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1999-10-19 21:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-18 16:15 $0.02 suggestion for the Printf module Alain Frisch
1999-10-19 19:15 ` William Chesters
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox