0

How do I allow rtop to discover my src file directory?

I found an option -I and hoped that rtop -I src would load my src files in rtop but it still isn't able to find them.

eg. src/lib.re:

let foo = 1;

Run command:

rtop -I src

Reason # open Lib;
Error: Unbound module Lib
glennsl
  • 28,186
  • 12
  • 57
  • 75
aqui8
  • 511
  • 3
  • 11
  • 1
    Note: question was also asked in https://reasonml.chat/t/how-to-include-src-files-in-rtop/2227 – Yawar Feb 23 '20 at 17:07
  • 1
    Thanks, didn't know which one was the official channel to ask questions. I should have linked them together (like you have done) at least though – aqui8 Feb 23 '20 at 22:53

1 Answers1

0

open is a language feature that doesn't know anything about the file system. You'll have to use a special directive instead to load the module from a file.

utop/rtop mostly uses the same directives as the ocaml toplevel, which are documented in the OCaml manual, here.

If the module has been compiled, you can load the .cmo or .cma using the #load directive:

#load "filename";;

If that module depends on other modules, you can use #load_rec instead to load them recursively.

If your code has not been compiled, and since you open it immediately, you can also use the #use directive:

#use "filename";;

Or if you want to load it as if was a top-level module, use #mod_use instead.

glennsl
  • 28,186
  • 12
  • 57
  • 75
  • Yeah I stumbled on that as well but I couldn't find an easy way to load everything at once like "dune utop". There's a pull request in dune for rtop though, so maybe that's the best way to go. I was just wondering if there was support for something like that without dune or esy. Perhaps I can write a script that creates an init file of some sort that automatically includes all the src modules – aqui8 Feb 23 '20 at 22:59