# Use\_module sometimes loads from current working directory

**URL:** <https://swi-prolog.discourse.group/t/use-module-sometimes-loads-from-current-working-directory/7589>\
**Category:** General\
**Created:** [July 11, 2024, 4:54am UTC](https://swi-prolog.discourse.group/t/use-module-sometimes-loads-from-current-working-directory/7589 "2024-07-11T04:54:05Z")\
**Posts on this page:** 1\
**Showing post:** 28

<div class="post-metadata">

**Author:** ![stassa.p](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/stassa.p/32/712_2.png) [@stassa.p](https://swi-prolog.discourse.group/u/stassa.p)\
**Post date:** [August 24, 2024, 10:52am UTC](https://swi-prolog.discourse.group/t/use-module-sometimes-loads-from-current-working-directory/7589/28 "2024-08-24T10:52:11Z")

</div>

> [@peter.ludemann](#):
>
> The notion of `cwd` is somewhat meaningless when a program is started by clicking on an icon, so I think it’s best to not have `cwd` in file searches (e.g., should `cwd` be the user’s “home”, where the program is, or where the clicked file is?)

Yes, I think this is how I understand it also. Maybe it’s idiosyncratic but if I’m working on the command line I never have any doubts what is the cwd. For example, if I `cd` to `/usr` and do an `ls .` I expect to see the contents of `/usr`. If I’m in doubt where I am there’s `pwd`. So in that case the cwd is clearly the path we could say the current terminal process is running from (even if that’s not what is really happening internally; at the user level, that’s what it looks like).

The problems begin if a process is started from a file called from another process. In that case there is no clear cwd: is it the file’s path, or the path of the process calling the file? I think that’s what you’re pointing out. But I don’t see how there can be an absolute, in the sense of objective, answer to that. @jan says above that most systems used to go one way, now they go the other way, so I guess it’s a kind of trend, like it’s a trend nowadays to “prefer composition over inheritance” in OOP circles (or has the trend changed yet?).

Btw, my original query, in the other post I linked, was about the different behaviour between `ls` and `use_module/1` in SWI. It seems getting it right _and_ consistent is going to be a big headache for @jan.

> [@Difference between ls/1 and use\_module/1 when finding a module](https://swi-prolog.discourse.group/t/difference-between-ls-1-and-use-module-1-when-finding-a-module/7669):
>
> After updating to the latest daily build for windows I get an error when I load a module using an explicit path, like “lib/module.pl” but not when I use a user-set file search path like “lib(‘module.pl’)”. At the same time, ls/1 can find the file with both paths. Here’s what the whole setup looks like on disk: . │ config.pl │ load.pl │ ├───lib │ target\_module.pl │ └───src module\_path.pl Here’s what the error looks like. Below, the module\_path.pl module is trying to load th…

---

_[View the full topic](https://swi-prolog.discourse.group/t/use-module-sometimes-loads-from-current-working-directory/7589)._
