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 PAA28903; Mon, 29 Sep 2003 15:16:55 +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 PAA17013 for ; Mon, 29 Sep 2003 15:16:54 +0200 (MET DST) Received: from mail.messagingengine.com (out1.smtp.messagingengine.com [66.111.4.25]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8TDGqH20327 for ; Mon, 29 Sep 2003 15:16:53 +0200 (MET DST) Received: from mail.messagingengine.com (localhost [127.0.0.1]) by localhost.localdomain (Postfix) with ESMTP id 33063233551 for ; Mon, 29 Sep 2003 09:16:51 -0400 (EDT) Received: from 10.202.2.150 ([10.202.2.150] helo=mail.messagingengine.com) by messagingengine.com with SMTP; Mon, 29 Sep 2003 09:16:51 -0400 X-Epoch: 1064841411 X-Sasl-enc: wyzBZgLRh/G7CazQzZWEuw Received: from [192.168.0.135] (f07v-10-82.d1.club-internet.fr [212.194.141.82]) by mail.messagingengine.com (Postfix) with ESMTP id EAED723B02F for ; Mon, 29 Sep 2003 09:16:49 -0400 (EDT) Date: Mon, 29 Sep 2003 15:16:38 +0200 (CEST) From: Martin Jambon X-X-Sender: martin@pc-bioinfo1 To: caml-list@inria.fr Subject: [Caml-list] Printing text with holes Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Loop: caml-list@inria.fr X-Spam: no; 0.00; dynamically:01 printf:01 printf:01 pervasives:01 pervasives:01 camlp:01 bazar:01 int:01 int:01 tar:01 jambon:02 jambon:02 string:03 string:03 arguments:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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. Printf is not satisfying for this kind of task because the formatting directives are far from the arguments: adding, removing or swapping parameters in the text becomes really difficult with long text and several arguments unless you make the text completely unreadable. The solution I adopted some time ago is the following: intead of this: printf "Hello %s %s! It is %i o'clock." first_name last_name time we write: << Hello $first_name $last_name! It is $int{time} o'clock. >> which is converted into let _ = Pervasives.print_string "Hello "; Pervasives.print_string first_name; Pervasives.print_string " "; Pervasives.print_string last_name; Pervasives.print_string "! It is "; print_int time; Pervasives.print_string " o'clock." Any function prefixed by print_ can be defined and used as a `format specifier'. It is also possible to pass several arguments to one function: << $x{arg1 arg2} >> is equivalent to print_x arg1 arg2 but << ${"a" ^ "b"} >> becomes print_string ("a" ^ "b") << $data.field >> becomes print_string data.field Does anyone need this kind of approach? Any better ideas? I put my implementation here (it is quite ugly, I still ignore everything about Camlp4): http://martin.jambon.free.fr/bazar/printfer.tar.gz -- Martin ------------------- 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