Difference between ls/1 and use_module/1 when finding a module

Here’s another little gotcha that I found today. Below, the first bit of syntax, with the path as a quoted atom, raises an error when I try to pass it to use_module/1, whereas the second bit of syntax, with the path as a //2 term does not raise any errors:

% Raises error when atomic path is passed to use_module/1
experiment_file('lib/grid_master/data/solvers/grid_solver.pl',grid_solver).

% Raises no error:
experiment_file(lib/grid_master/data/solvers/grid_solver,grid_solver).

It might seem strange to pass the path explicitly as a quoted atom, as in the first uncommented line above, but the reason was that I was unsure whether that path would be recognised as a path if I passed it around as a term, rather than an atom.

Also, in general my intuition with SWI-Prolog is that paths are relative to the SWI-Prolog process, rather than relative to any source files. So I load all my source files with a “project load file” that also sets file search paths. I start my project by consulting the project load file. Then I refer to loaded files assuming paths are relative to the project load file. After the recent changes this tactic has caused quite a few errors.

My project load file is quite an informal thing so I guess everyone’s use cases will differ but knowing that every path I may pass around my project is relative to the directory where the project load file is run from gave me a certain sense of security.

Btw, here’s my project load file for Louise:

I guess such a thing is more common when one is using a full-blown IDE to manage a project, like people do with Visual Studio etc.

Anyway I would maybe argue for making everything relative to the initial process, but I suppose that’s a bit like a debate between which one is best, chocolate or strawberry ice cream.

Strawberry. Yech. :stuck_out_tongue: