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 TAA07855; Mon, 29 Sep 2003 19:00:22 +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 TAA10699 for ; Mon, 29 Sep 2003 19:00:20 +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 h8TH0HH14387; Mon, 29 Sep 2003 19:00:17 +0200 (MET DST) Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA27229; Mon, 29 Sep 2003 19:00:17 +0200 (MET DST) From: Pierre Weis Message-Id: <200309291700.TAA27229@pauillac.inria.fr> Subject: Re: [Caml-list] Printing text with holes In-Reply-To: from Martin Jambon at "Sep 29, 103 03:16:38 pm" To: martin_jambon@emailuser.net (Martin Jambon) Date: Mon, 29 Sep 2003 19:00:16 +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 dynamically:01 camlp:01 bazar:01 3.07:01 buffer:01 val:01 appends:01 buffer:01 parentheses:01 cristal:01 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. [...] > 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 Many people use the same approach with dollars. In the 3.07 release of Objective Caml there is some support to easily obtain such a feature: in the interface of the module Buffer, we find val add_substitute : t -> (string -> string) -> string -> unit (** [add_substitute b f s] appends the string pattern [s] at the end of the buffer [b] with substitution. The substitution process looks for variables into the pattern and substitutes each variable name by its value, as obtained by applying the mapping [f] to the variable name. Inside the string pattern, a variable name immediately follows a non-escaped [$] character and is one of the following: - a non empty sequence of alphanumeric or [_] characters, - an arbitrary sequence of characters enclosed by a pair of matching parentheses or curly brackets. An escaped [$] character is a [$] that immediately follows a backslash character; it then stands for a plain [$]. Raise [Not_found] if the closing character of a parenthesized variable cannot be found. *) This may be used to create strings with $identifiers to expand in them. 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