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 QAA00059; Mon, 17 Jun 2002 16:47:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA00172 for ; Mon, 17 Jun 2002 16:47:15 +0200 (MET DST) Received: from cirse.saclay.cea.fr (cirse.saclay.cea.fr [132.166.192.127]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g5HElE126687 for ; Mon, 17 Jun 2002 16:47:14 +0200 (MET DST) Received: from argiope.saclay.cea.fr (argiope.saclay.cea.fr [132.166.192.108]) by cirse.saclay.cea.fr (8.12.2/8.12.2/CEAnet-Internet.1.0) with ESMTP id g5HElAZj019181 for ; Mon, 17 Jun 2002 16:47:10 +0200 (MEST) Received: from muguet.saclay.cea.fr (unverified) by argiope.saclay.cea.fr (Content Technologies SMTPRS 4.2.10) with ESMTP id for ; Mon, 17 Jun 2002 16:34:16 +0200 Received: from is002254.saclay.cea.fr (is002254.saclay.cea.fr [132.166.134.67]) by muguet.saclay.cea.fr (8.12.2/8.12.2/CEAnet-Interne.1.0) with ESMTP id g5HEcjkW001345; Mon, 17 Jun 2002 16:38:45 +0200 (MEST) Received: from basile by is002254.saclay.cea.fr with local (Exim 3.35 #1 (Debian)) id 17Jxea-0007kt-00; Mon, 17 Jun 2002 16:38:48 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <15629.62581.329369.773250@is002254.saclay.cea.fr> Date: Mon, 17 Jun 2002 16:38:45 +0200 To: caml-list@inria.fr Subject: [Caml-list] Camlp4: varargs ie a la Printf X-Mailer: VM 7.03 under Emacs 21.2.1 From: Basile STARYNKEVITCH Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Dear All Camlp4-ers, I am using OCaml 3.04 (with the standard Camlp4 3.04) I do know that the CVS Ocaml does have a Printf.kprintf function which would make my problem easier to solve. My problem is how to have a sort of variadic macro. (**** file pa_trace.ml *****) (****** this file provide a tracing preprocessor facility; at compile time, you can preprocess with the -Tfoo flag (there can be several such flags); in the preprocessed source, you can code trace FOO "i=%d x=%g" i x end which is preprocessed to if (Trace.Tracing.foo) then Trace.trace Trace.Level.Foo (Printf.sprintf "i=%d x=%g" i x) ; if preprocessed with -Tfoo or just to the unit value () otherwise ******) module SetOfName = Set.Make( struct type t= string;; let compare s1 s2 = Pervasives.compare s1 s2 end);; let trset = ref SetOfName.empty;; (* function to add tracing *) let add_tracing trname = trset := SetOfName.add trname !trset ;; let is_traced trname = (SetOfName.is_empty !trset) || (SetOfName.mem trname !trset) ;; EXTEND GLOBAL: Pcaml.expr ; Pcaml.expr: LEVEL "top" [ [ "trace" ; trid = UIDENT ; fmt = STRING ; args = LIST0 Pcaml.expr ; "end" -> let lctrid = String.lowercase trid in Printf.eprintf "trace %s does not work yet\n" lctrid; if is_traced lctrid then <:expr< if Trace.Tracing.$lid:lctrid$ then Trace.trace Trace.Level.$lid:lctrid$ (Printf.sprintf $str:fmt$ (**** WHAT SHOULD BE ADDED HERE? *****) ) else () >> else <:expr< () >> ] ] ; END; (****** end of file *****) My problem is to produce a quotation of a list of expressions (and not a quotation of a list expression). What should I put in place of the comment WHAT SHOULD BE ADDED HERE? trace FOO "i=%d x=%g" i x end I am not sure to understand what the antiquotation $list:l$ is for. With the future Ocaml I would just expand trace FOO "i=%d x=%g" i x end to if (Trace.Tracing.foo) then Printf.kprintf (Trace.ktrace Trace.Level.Foo) "i=%d x=%g" i x which I believe should be simpler. Perhaps the question is easy, but it is really too hot now here..... so I am coding poorly. If Ocaml3.05 is out soon I might use kprintf anyway.... Otherwise if some people have some tracing or logging macros (which they accept to share into a GPL-ed code?) I would be grateful. Thanks. -- N.B. Any opinions expressed here are only mine, and not of my organization. N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA. --------------------------------------------------------------------- Basile STARYNKEVITCH ---- Commissariat à l Energie Atomique * France DRT/LIST/DTSI/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX phone:+33 1,6908.6055; fax: 1,6908.8395 home: 1,4665.4553; mobile: 6,8501.2359 work email: Basile point Starynkevitch at cea point fr home email: Basile at Starynkevitch point net ------------------- 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