caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Basile STARYNKEVITCH <basile.starynkevitch@cea.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Camlp4: varargs ie a la Printf
Date: Mon, 17 Jun 2002 16:38:45 +0200	[thread overview]
Message-ID: <15629.62581.329369.773250@is002254.saclay.cea.fr> (raw)

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


             reply	other threads:[~2002-06-17 14:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-17 14:38 Basile STARYNKEVITCH [this message]
2002-06-17 14:59 ` Alain Frisch
2002-06-17 16:20   ` John Malecki
2002-06-18  6:27 ` Daniel de Rauglaudre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15629.62581.329369.773250@is002254.saclay.cea.fr \
    --to=basile.starynkevitch@cea.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).