[{"data":1,"prerenderedAt":124},["ShallowReactive",2],{"\u002Focaml-eval":3},{"id":4,"title":5,"body":6,"createdAt":112,"description":103,"draft":113,"extension":114,"image":115,"mastodonThread":115,"meta":116,"navigation":117,"path":118,"seo":119,"stem":120,"tags":121,"updatedAt":112,"__hash__":123},"content\u002FOCaml Eval.md","OCaml_Eval",{"type":7,"value":8,"toc":102},"minimark",[9,14,24,29,50,54,58,61,83,99],[10,11,13],"h2",{"id":12},"evaluate-ocaml-code-dynamically","Evaluate OCaml Code Dynamically",[15,16,17,18,23],"p",{},"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 ",[19,20,22],"a",{"href":21},"\u002Fgenetic-programming","Genetic Programming",", for example). Based on some code in the interactive toplevel module this isn't hard to do.",[25,26,28],"h3",{"id":27},"get-the-code","Get The Code",[30,31,32,41],"ul",{},[33,34,35,36],"li",{},"Source directory: ",[19,37,38],{"href":38,"rel":39},"http:\u002F\u002Fthelackthereof.org\u002Fprojects\u002Focaml\u002Feval\u002F",[40],"nofollow",[33,42,43],{},[44,45,46,47],"nowiki",{},"\ndarcs get \n",[19,48,38],{"href":38,"rel":49},[40],[25,51,53],{"id":52},"usage","Usage",[10,55,57],{"id":56},"evaltestml","evaltest.ml",[15,59,60],{},"open Eval",[15,62,63,64,67,68,70,71,73,74,76,77,79,80,82],{},"let _ =",[65,66],"br",{},"\neval_reset();",[65,69],{},"\nevalp \"let add1 x = x +1;;\";",[65,72],{},"\nlet n : int = eval \"n\" \"let n = add1 2;;\" in",[65,75],{},"\nprint_string \"n = \";",[65,78],{},"\nprint_int n;",[65,81],{},"\nprint_newline()",[15,84,85,86,88,89,95,96,98],{},"Result:",[65,87],{},"\nbrock@ihd103:",[90,91,92,93,88],"del",{},"\u002Ftmp$ ocamlc -o evaltest toplevellib.cma eval.ml evaltest.ml",[65,94],{},"\u002Ftmp$ .\u002Fevaltest",[65,97],{},"\nn = 3",[15,100,101],{},"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.",{"title":103,"searchDepth":104,"depth":104,"links":105},"",2,[106,111],{"id":12,"depth":104,"text":13,"children":107},[108,110],{"id":27,"depth":109,"text":28},3,{"id":52,"depth":109,"text":53},{"id":56,"depth":104,"text":57},"2004-04-18T13:48-04:00",false,"md",null,{},true,"\u002Focaml-eval",{"title":5,"description":103},"OCaml Eval",[122],"project","tPJaLSGO30QpY10ms1tPeVCGpte7yPa50sN3yflH_18",1778988312478]