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] Printing text with holes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-09-29 (16:34)
From: Brian Hurt <bhurt@s...>
Subject: Re: [Caml-list] Printing text with holes
On Mon, 29 Sep 2003, Martin Jambon wrote:

> Hello,
> I am curious to know what people use to print long text written in a
> natural language, and containing many holes, like dynamically generated
> web pages.

I agree.  I think printf is a horrible way to do output.  Reasons include, 
but are not limited to, the fact that you are basically creating a new 
"mini-language" (the formatting language) which has to be type checked 
etc. seperately from the main language, that the values being put into the 
string are listed far from their positions in the string (your problem) 
leading to missing parameters, parameters in the wrong order, etc.

> The solution I adopted some time ago is the following:

IMHO, this is certainly a better solution to the problem.  But it does 
need p4 (I think).

What might be even better is an output operator, ala C++.  Maybe something 

let ( <$ ) chan str = output_string chan str; chan

This would allow you to do:
let _ = stdout <$ "Hello " <$ first_name <$ " " <$ last_name <$ "! It is "
<$ (string_of_int time) <$ " o'clock.\n";;

Not quite as clean, but close, and it doesn't require p4.


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