ocaml doesn't load .ocamlinit in script mode
ocaml
Solution
I think that's a "bug" (or at least unexpected behaviour) in the toplevel. This could be fixed in future versions of OCaml. I don't have a satisfying workaround to propose, besides `ocaml -noprompt < test.ml` (which is not equivalent as you will get some noisy output from the toplevel instead of just your file executed), or of course compiling the program and running it (which may be as simple as `ocamlbuild test.byte && ./test.byte`).
Problem
I find that when I run `ocaml` in terminal, ie, in interactive mode, it will load `.ocamlinit`. However, when I run `ocaml test.ml`, ie, in script mode, it doesn't load `.ocamlinit` file. This actually causes some trouble for me, since I have the following setup in my `.ocamlinit`: ``` let () = try Topdirs.dir_directory (Sys.getenv "OCAML_TOPLEVEL_PATH") with Not_found -> () ;; #use "topfind";; #thread;; #camlp4o;; #require "core.top";; #require "core.syntax";; ``` So when I run in interactive mode, `#use "topfind"` will be executed and I can open other libraries in my code. But as `.ocamlinit` is not loaded in script mode, when I run `ocaml test.ml` in terminal, with `test.ml` like this: open Core.Std;; let () = print_endline "hello world" It will fail with error: `"Error: Unbound module Core"`. My question is: - How to fix this so that when running `ocaml` in script mode, the `.ocamlinit` file will also be loaded? - Why the ocaml toplevel system doesn't load `.ocamlinit` file in script mode? ps. The OCaml version is `4.01.0`