Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007873OCamltoplevelpublic2018-11-17 19:042018-11-22 09:00
ReporterLoup Vaillant 
Assigned Todra 
Platformx86-64OSUbuntu GNU/LinuxOS Version18/04 LTS
Product Version4.05.0 
Target VersionFixed in Version 
Summary0007873: ocamlmktop has no way to avoid the need for the #directory directive
DescriptionMaybe it's a missing feature instead of a genuine bug, but it nevertheless halves the usefulness of ocamlmktop.

The -I option can be used to search named object files in various directories, but has no effect whatsoever inside the REPL itself. The user is still forced to type the relevant #directory directive.

Without a way to avoid "#directory "dir";;" all the time, ocamlmktop is rendered much less useful.

Now maybe it isn't the job of the -I option (though I wonder why it wouldn't be, considering how ocamlc works). But then it would be very nice to have a command line option to generate #directory directives directly.
Steps To ReproduceLet's assume we have an object file in another directory:

    $ ls lib

Here's an example session:

    $ ocamlmktop -I lib utils.cmo
    $ ./a.out
            OCaml version 4.05.0

    # open Utils;;
    Error: Unbound module Utils
    # #directory "lib";;
    # open Utils;;

Most frustrating.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
dra (developer)
2018-11-17 20:33

ocamlmktop's principal purpose is allow for toplevels on systems without dynamic C loading (e.g. for stubs).

What you want to accomplish should be done by linking an extra module in whose code includes Topdirs.dir_directory "utils".

However, I find on my system that this seems to have been broken since 4.06
dra (developer)
2018-11-17 20:34

As an aside, turning the -I options passed to ocamlmktop into #directory's for the compiled toplevel is not in general a sensible change - -I is being used there to locate .cmo and .cma files for linking.
dra (developer)
2018-11-17 22:37

Regression was introduced in 4.06.0 by GPR#1041 ( [^]). I have a hacky fix by replaying calls to Topdirs.dir_directory after Compmisc.init_path is called in Topmain.main (the call to that, incidentally, is in the wrong place too, since it should appear before Topmain.prepare as that calls Toploop.set_paths which is also being overridden by re-running Compmisc.init_path).

The fix I have works, but I think it would be better to revisit how Compmisc.init_path is used - it remains bad that Compmisc.init_path refers to command line arguments before they've actually been parsed.
Loup Vaillant (reporter)
2018-11-17 23:47

Wrote a long reply, it got deleted by bad software. I'm getting pissed at Mantis.

I'll try to learn more about this "Topdir" thing (I have version 4.0.5, it should work). Quite a shame the ocamlmktop documentation doesn't mention it anywhere. My use case is the most common one, what you mention seems to be common knowledge, yet the documentation is utterly silent. I suggest the manual be updated.

Also, I fail to see the utility of *not* making modules available even though they were explicitly linked with -I. Do you know of such a use case? If there isn't, the -I option should be modified. If there is, ocamlmktop still needs a dedicated option.

I love OCaml, but stuff like his hurts adoption.
Loup Vaillant (reporter)
2018-11-17 23:53

Okay, Topdir isn't a thing on the OCaml manual, or even on my search engine.

Does anyone actually *use* ocamlmktop?
dra (developer)
2018-11-20 19:07

Any chance we could tone the grumpiness down a little? Writing toplevels is I think fairly niche - what's the use case for this, out of curiosity?

Topdir won't be a thing - it's called Topdirs, but it's a compiler internal module so it won't be in the manual. However, Googling ocaml topdirs gave me loads of results. It contains the functions corresponding to the # directives in the toplevel.

Changing -I as you request is a breaking change, so I don't need a use-case; that's more than enough! Given that ocamlmktop is just a thin wrapper around calling the main compiler, I'm not personally persuaded of the need for the complexity, but I definitely agree that adding the example to the manual would be useful.
dra (developer)
2018-11-20 19:07

See also [^]
Loup Vaillant (reporter)
2018-11-21 00:37
edited on: 2018-11-21 00:39

> Writing toplevels is I think fairly niche

W- What? Are you denying the outstanding usefulness of the REPL, of automatically loading stuff into said REPL, or actually developing a toplevel? I personally believe in the first, think the second is a major convenience, and I did the third when I implemented a language for non-programmers (so they could control some testing environment) because the client asked for a REPL.

> what's the use case for this, out of curiosity?

The most mundane thing: writing modules one by one, and once a module is complete add it to the list of modules to load automatically in the REPL. This automatic loading grows more useful as the projects grows bigger.

> Googling ocaml topdirs gave me loads of results.

That's just you. Google has trapped you into your own bubble, and biased your search results towards your interests. Try from your relative's computers. Or try with DuckDuckGo, which usually finds what I need (and serves everyone with the same results). Or Bing, which if you never use it may not have a bubble for you yet: [^] [^]

Google has another bubble for me, and it doesn't include Topdirs. I won't find it on my own, I need a direct link.

dra (developer)
2018-11-21 20:00

You could also solve it with a .ocamlinit file which would even save having to remember to rebuild the toplevel after you add a new module. Or you could even go full-hipster and use dune and utop which will do the whole thing for you ( [^]).

You'll find topdirs.mli in your OCaml Standard Library directory, but you'll forgive me for not providing a URL to your computer. Incidentally, DuckDuckGo, which I've never used, has an example from for Gtk which shows exactly how to use it. But perhaps DuckDuckGo secretly gets my profile from Google...
Loup Vaillant (reporter)
2018-11-21 21:31

OK, thanks for the tip. I'll look into my standard library.

I recall the GTK link to DuckDuckGo, I just failed to notice its relevance. An "introduction to GTK" didn't look like relevant Topdirs documentation… I something dedicated to Topdirs. I'll take a closer look.

the .ocamlinit file is yet another thing I didn't know about, and the search results are not exactly abundant (though I did find some stuff).
dra (developer)
2018-11-21 21:52

.ocamlinit is documented in the manual ( [^]) _before_ ocamlmktop!
Loup Vaillant (reporter)
2018-11-22 09:00


- Issue History
Date Modified Username Field Change
2018-11-17 19:04 Loup Vaillant New Issue
2018-11-17 19:23 gasche Reproducibility have not tried => always
2018-11-17 20:33 dra Note Added: 0019463
2018-11-17 20:34 dra Note Added: 0019464
2018-11-17 22:37 dra Note Added: 0019465
2018-11-17 23:47 Loup Vaillant Note Added: 0019466
2018-11-17 23:53 Loup Vaillant Note Added: 0019467
2018-11-20 19:07 dra Note Added: 0019469
2018-11-20 19:07 dra Note Added: 0019470
2018-11-20 19:07 dra Assigned To => dra
2018-11-20 19:07 dra Status new => assigned
2018-11-20 19:07 dra Status assigned => acknowledged
2018-11-20 19:08 dra Severity minor => feature
2018-11-20 19:08 dra Category misc => toplevel
2018-11-21 00:37 Loup Vaillant Note Added: 0019473
2018-11-21 00:39 Loup Vaillant Note Edited: 0019473 View Revisions
2018-11-21 20:00 dra Note Added: 0019475
2018-11-21 21:31 Loup Vaillant Note Added: 0019477
2018-11-21 21:52 dra Note Added: 0019478
2018-11-22 09:00 Loup Vaillant Note Added: 0019479

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker