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] camlp4: ONCE construct
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-01-10 (19:14)
From: jehenrik <jehenrik@y...>
Subject: [Caml-list] camlp4: ONCE construct

I would like to write a Camlp4 construct which causes its argument to 
only be evaluated once.  Eg:

			ONCE Pcre.regexp "([0-9]+)"

would be transformed to:

let gensym000 = Pcre.regexp "([0-9]+)";;

but I don't see a way to get a nonlocal transformation like that.  One 
way would be if the system had a way to side-effect out a new toplevel 
let while the expressions were transforming.  I suspect that facility 
does not exist.  Another way would be to have a second keyword 
(ONCEBLOCK or something?) that would go where the let bindings 
eventually would, which could take as an argument the entire expression 
tree containing ONCE declarations.  Then after a complicated recursive 
parse on all the syntactic constructs, all the ONCEs could be located, 
enumerated, and removed.

Note that I don't want to "memoize," or create a thunk which when 
evaluated the first time does something complicated and all subsequent 
times remembers what it did the first time.  That still requires 
manually writing the let statements in a different code location.  My 
goal is to improve readability by putting my regexps where they matter, 
not several screens up just so that they get cached at runtime.

Thanks for any advice,

Jeff Henrikson

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