English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
String representation of the expression: may camlp4 help?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-08-15 (20:14)
From: Martin Jambon <martin_jambon@e...>
Subject: Re: [Caml-list] String representation of the expression: may camlp4 help?
On Mon, 15 Aug 2005, Dmitri Boulytchev wrote:

>   Hello everybody,
>   I'm looking for the way to get string representation of the OCaml 
> expression
>   at compile-time to facilitate test writing. Consider an example:
>        let repr, value = WITH_REPR (1+2) in
>        Printf.printf "%s=%d" repr value
>   Here WITH_REPR is a meta-construction that returns ("1+2", 3) (generally
>   speaking WITH_REPR(c) whould return (string * type_of c)).
>   Is there some convinient way to do this? May camlp4 help?

Have a look at the pretty-printing functions that pr_o.ml 
provides (from your Camlp4 installation). You can probably hack your own 
(expr -> string) function if it does not already exist.


Martin Jambon, PhD