== Evaluate OCaml Code Dynamically ==
This is a horrid thing that you probably shouldn't do. That said -- sometimes it would be nice to evaluate some arbitrary OCaml code at runtime (in Genetic Programming, for example). Based on some code in the interactive toplevel module this isn't hard to do.
let _ =
evalp "let add1 x = x +1;;";
let n : int = eval "n" "let n = add1 2;;" in
print_string "n = ";
/tmp$ ocamlc -o evaltest toplevellib.cma eval.ml evaltest.ml/tmp$ ./evaltest
n = 3
Just like magic. Be sure to compile toplevellib.cma in with your stuff. Oh, and I'm pretty sure this only works in bytecode. Sorry.