Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Question about camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re: [Caml-list] Question about camlp4
Hi,

On Mon, Mar 25, 2002 at 11:13:48AM +0100, Frederic Tronel wrote:

> spec_exp:  [[ "specification" ; name = LIDENT; "[" ; g = LIST0 gate_exp
> SEP "," ; "]" -> <:expr<Specification $str:name$ $list:g$ >> ]] 

There is no node "list" in the abstract syntax tree. The antiquotation
of type "list" cannot be used to create the tree node of a list.

To build your your list node, you have to apply the contructors :: and []:

  List.fold_right (fun x l -> <:expr< [$x$ :: $l$] >>) g <:expr< [] >>

Your code could then be:

  spec_exp:
     [[ "specification" ; name = LIDENT; "[" ; g = LIST0 gate_exp
        SEP "," ; "]" ->
          let e =
            List.fold_right (fun x l -> <:expr< [$x$ :: $l$] >>) g
              <:expr< [] >>
          in
          <:expr<Specification $str:name$ $e$ >> ]] 

Note: this is different if you would want to create an array, because
arrays are built by one construction. You can write:
    <:expr<Specification $str:name$ [| $list:e$ |] >>

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
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