Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 
like:

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.

Brian


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