Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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:

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

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

Any direction you could provide on this would be great!

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: