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
Which camlp variant?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-11-09 (10:40)
From: tmp123 <tmp123@m...>
Subject: Re: [Caml-list] Which camlp variant?
Thanks a lot,

The solution from Chris covers all the requirements. A reduced 
subvariant of its "pa_log", compatible with camlp4 and adapted to this 
development has been written (probably with some errors ;-)

open Camlp4.PreCast;
open Syntax;

(* Apply a function to a list of arguments *)
value app_to_list lst _loc =
    (fun f x -> <:expr< $f$ $x$ >>)
    <:expr< Tools.log_printf >> lst;


  expr: LEVEL "apply"
  [ [ LIDENT "log"; e = LIST0 expr LEVEL "." ->
        <:expr< Tools.log_internal ( fun () -> $app_to_list e _loc$ ) >>
  ] ]

It needs the support of a module "Tools" with two functions 
"log_internal" and "log_printf". By example:

value log_active = ref False;

value log_printf = Printf.printf;

value log_internal e =
  if log_active.val then
    flush stdout;
  else ();

The syntax in the callers is:

log "something is %d" 12;

Thanks to all persons who has colaborate in this subject.


Christopher L Conway wrote:

>This may not have been true of the version that was on the website
>previously. I've just updated it to my latest version, which does
>indeed work with camlp5.
>On Nov 7, 2007 7:48 PM, Christopher L Conway <cconway@cs.nyu.edu> wrote:
>>pa_log is compatible with camlp5. In fact, that's what I use. Just
>>s/4/5/ all commands invoking camlp4.
>>On Nov 7, 2007 1:25 PM, tmp123 <tmp123@menta.net> wrote:
>>>The module "pa_log" proposed by Mr. Conway seems very near to the
>>>objective of my previuos post.
>>>The objective  now is expand a line like: DEBUG 3 "%d\n" 14
>>>to: if debug.val then logint 3 ( fun () -> Printf.printf "%d\" 14  )
>>>else ();
>>>However, it is necessary to migrate the module to new camlpx .
>>>Please, could someone give any advice about the current options: camlp4
>>>or camlp5? PreCast? Functorial?
>>>Thanks a lot.
>>>Caml-list mailing list. Subscription management:
>>>Archives: http://caml.inria.fr
>>>Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>>Bug reports: http://caml.inria.fr/bin/caml-bugs