Created
October 26, 2015 22:40
-
-
Save scemama/a4003f8a1b923745a141 to your computer and use it in GitHub Desktop.
Evaluate a string in OCaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* http://stackoverflow.com/questions/33291754/eval-a-string-in-ocaml *) | |
#require "compiler-libs" (* Assuming you're using utop, if compiling then this is the package you need *) | |
let eval code = | |
let as_buf = Lexing.from_string code in | |
let parsed = !Toploop.parse_toplevel_phrase as_buf in | |
ignore (Toploop.execute_phrase true Format.std_formatter parsed) | |
eval "let () = print_endline \"hello\";;" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment