From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA21124; Mon, 29 Sep 2003 23:25:33 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA14391 for ; Mon, 29 Sep 2003 23:25:32 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8TLPSH06437; Mon, 29 Sep 2003 23:25:29 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA18034; Mon, 29 Sep 2003 23:25:28 +0200 (MET DST) From: Pierre Weis Message-Id: <200309292125.XAA18034@pauillac.inria.fr> Subject: Re: [Caml-list] Printing text with holes In-Reply-To: from Martin Jambon at "Sep 29, 103 08:57:36 pm" To: martin_jambon@emailuser.net (Martin Jambon) Date: Mon, 29 Sep 2003 23:25:28 +0200 (MET DST) Cc: caml-list@inria.fr X-Mailer: ELM [version 2.4ME+ PL28 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pierre:01 weis:01 pierre:01 weis:01 caml-list:01 ranking:99 vol:99 vol:99 ranking:99 expressing:01 hash:01 dollar:99 buffer:01 subtitute:01 buffer:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk [...] > Well, I just extracted some code from one of my CGI programs. > Here, the purpose is to print one line of an HTML table, where one column > should appear in bold face (using arrays containing strings "" or "" or > ""). > Here is the code: > > let print_binary_patch id bb be ranking p = > let volume1 = p.patch_1.volume in > let volume2 = p.patch_2.volume in > let vol_percentage1 = p.patch_1.relative_volume *. 100. in > let vol_percentage2 = p.patch_2.relative_volume *. 100. in > > let print_option = function > None -> () > | Some s -> << ($s) >> in > << > > $int{ranking} $matched_tags{p} > [View] > [Quick view] > ${bb.(1)}$g{p.patch_global.patch_size}${be.(1)} > ${bb.(2)}$r1{vol_percentage1}% ($r1{volume1})${be.(2)} > ${bb.(3)}$r2{vol_percentage2}% ($r2{volume2})${be.(3)} > ${bb.(4)}$int{p.patch_1.pdb_group_number}${be.(4)} > ${bb.(5)}$int{p.patch_2.pdb_group_number}${be.(5)} > ${bb.(6)}$f3{p.patch_global.patch_sumo_score}${be.(6)} > > >> > > This does not look very beautiful, but for me it is important to have a > compact representation where one line of source code produces not less > than one line of output. This allows to have a global overview of the > output without having to run the program. > The above piece of code has 28 holes... that we must be able to modify at > any time, just because we don't print all the data. > > I would like to thank everyone for expressing their opinion on the > subject! > > -- Martin In this case, I surely would use a template file, read the template in memory, build the substitution function (with a hash table ?) for the dollar identifiers and then use string substitution with Buffer.add_subtitute to produce the output in a Buffer.t value. Hope this helps, Pierre Weis INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/ ------------------- 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