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 (17:00)
From: Pierre Weis <pierre.weis@i...>
Subject: Re: [Caml-list] Printing text with holes

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

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

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