Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] embedding OCaml into C on win32
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julie Farago <farago@e...>
Subject: [Caml-list] camlp4 and anonymous function naming
camlp4 hackers,

I am trying to use camlp4 to name anonymous functions. I want to take code
that in the form:
fun <args> -> <body>

and convert it to:
let anonfunc<number> <args> = <body> in anonfunc<number>

I've read over the camlp4 tutorial and have some sense of how to do this,
but am getting stuck because I do not know the correct syntax to use. I
currently am extending the grammar with:

EXTEND
 expr:
   [[ "fun" ; vars = LIST1 LIDENT ; "->" ; e = expr ->
         givenames loc vars e ]]
 ;
END;;

and then I try and re-write the anonymous function with:

let namefun =
  let cnt = ref 0 in
    fun var -> let x = incr cnt ; !cnt in
    var ^ "_genfun" ^ string_of_int x

let givenames loc vars e =
  let name = namefun "my" in
    <:expr<
      let $lid:name$ $vars$ = $e$
      in $lid:name$ >>

This code is, of course, wrong. The problem is that I cannot figure out
how to simply capture the args from the fun and place them back into the
let.

Any direction you could provide on this would be great!
-Julie

-------------------
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