Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] camlp4 and let binding...
[ 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] camlp4 and let binding...
Hi,

On Tue, Nov 26, 2002 at 03:29:09PM +1100, Pietro Abate wrote:
> 
> I wrote something that, of course, doesn't work. My major problems are about 
> the inner let definitions. How can I chain all let defintions in the list ?

I am not sure I understand what you want to do but this:

>             <str_item:<
>             value $lid:pref$ = $list:definition$ in
>             new rule(pattern,action) 
>             >>

is syntactically incorrect: you must not put "in" after a "value". If
you want to make a let..in inside (like in your example), you have to
make the variable "definition" a list of (patt * expr) and you can
write:

            <str_item:<
            value $lid:pref$ =
              let $list:definition$ in
              new rule(pattern,action)
            >>

If "definition" is, for example, the list: [(p1, e1); (p2; e2)] it is
equivalent to:

            <str_item:<
            value $lid:pref$ =
              let $p1$ = $e1$
              and $p2$ = $e2$ in
              new rule(pattern,action)
            >>

If you prefer a "let..in let.. in" instead of "let .. and .. in", you
have to write it explicitely:

            <str_item:<
            value $lid:pref$ =
              let $p1$ = $e1$ in
              let $p2$ = $e2$ in
              new rule(pattern,action)
            >>

If you want that, but you have a list of let..in with an unknown
number of elements, you have to do it with an iterator, e.g.:

     List.fold_right (fun (p1, e1) e -> <:expr< let $p1$ = $e1$ in $e$ >>)
       list <:expr< new rule(pattern, action) >>

-- 
Daniel de RAUGLAUDRE
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