Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Camlp4: varargs ie a la Printf
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Malecki <johnm@a...>
Subject: Re: [Caml-list] Camlp4: varargs ie a la Printf
Alain Frisch wrote (2002-06-17T16:59:05+0200):
 > On Mon, 17 Jun 2002, Basile STARYNKEVITCH wrote:
 > 
 > > 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'm not sure to understand how this is more difficult than the solution
 > with Printf.kprintf; in both case, you want to generate a 'varargs'
 > application, right ?  Or what is a "list of expressions" ?
 > 
 > Try something like:
 > 
 > List.fold_left (fun e_1 e_2 -> <:expr< $e_1$ $e_2$ >>)

Here is what i normally use in my parsers

  let expr_of_list loc l =
    let f e l = <:expr< [$e$ :: $l$] >> in
    List.fold_right f l <:expr< [] >>

as in

  cnds: [ [ cs = LIST1 cnd SEP "and" -> expr_of_list loc cs ] ];
-------------------
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