Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile from within the OCaml repl

Tags:

ocaml

I am using emacs with tuareg mode and I always have the ocaml repl opened inside emacs. I was wondering if there's a way of compiling basic OCaml test files from within the repl so I don't have to run the compilation as a system command.

like image 615
hyperboreean Avatar asked Nov 06 '22 07:11

hyperboreean


1 Answers

To my knowledge there isn't, but you can easily run compilation from within emacs.

If you use the M-x compile command (C-c C-c using the tuareg mode), the compilation is run in emacs "compile mode" which is rather nice to work with. In particular, it allows you to jump directly at the erroneous positions in the code in case of compilation error (M-x goto-next-error or "C-x `").

With the compile command, you choose the (shell) command to run the compilation. You can invoke the ocaml compiler directly (typically, ocamlc -c foo.ml), or use ocamlfind to facilitate compilation using external libraries, and even make or ocamlbuild to automate most of the compilation for you. Typically, if you have a small project using different source files, with a main.ml file, ocamlbuild main.byte will do the job of building an executable from it.

Edit : of course, you could call a system command from within the toplevel, using the Sys.command function. But I don't see the point.

like image 149
gasche Avatar answered Nov 13 '22 07:11

gasche