# Finding a module implicit dependencies

**URL:** <https://swi-prolog.discourse.group/t/finding-a-module-implicit-dependencies/1279>\
**Category:** Help!\
**Created:** [September 18, 2019, 8:56am UTC](https://swi-prolog.discourse.group/t/finding-a-module-implicit-dependencies/1279 "2019-09-18T08:56:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmoura](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/pmoura/32/11_2.png) [@pmoura](https://swi-prolog.discourse.group/u/pmoura)\
**Post date:** [September 18, 2019, 8:56am UTC](https://swi-prolog.discourse.group/t/finding-a-module-implicit-dependencies/1279/1 "2019-09-18T08:56:00Z")

</div>

What’s the most reliable way of finding a module implicit dependencies?

In the yesterday release of Logtalk 3.30.0 I’m using the following internal predicate in the SWI-Prolog adapter file:

```prolog
% '$lgt_find_module_predicate'(+atom, -atom, @callable)
%
% succeeds when Module:Predicate is visible in module Current

'$lgt_find_visible_module_predicate'(_Current, Module, Predicate) :-
	predicate_property(Predicate, implementation_module(Module)).

```

This predicate is used when compiling Prolog modules as Logtalk objects and the linter takes advantage of it to advise on missing `use_module/2` directives. Extensive testing suggests that the reported missing directives are accurate but I wonder if the above definition should take the source module into account or if there are any gotchas that I’m missing.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [September 18, 2019, 9:26am UTC](https://swi-prolog.discourse.group/t/finding-a-module-implicit-dependencies/1279/2 "2019-09-18T09:26:00Z")

</div>

> [@pmoura](#):
>
> What’s the most reliable way of finding a module implicit dependencies

What does that mean? I don’t really recall the history behind `implementation_module`. It seems to say `if we need this defined it will come from the indicated module'. Typically I use `imported\_from`, but this actually loads the dependency as a side-effect.

---

<div class="post-metadata">

**Author:** ![pmoura](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/pmoura/32/11_2.png) [@pmoura](https://swi-prolog.discourse.group/u/pmoura)\
**Post date:** [September 18, 2019, 9:33am UTC](https://swi-prolog.discourse.group/t/finding-a-module-implicit-dependencies/1279/3 "2019-09-18T09:33:36Z")

</div>

> [@jan](#):
>
> What does that mean?

Simple example:

```prolog
:- module(foo, [bar/2]).

bar(X, L) :-
    member(X, L).

```

The `foo` module have an implicit dependency on the `lists` module, which provides the `member/2` predicate.

> [@jan](#):
>
> I don’t really recall the history behind `implementation_module` . It seems to say `if we need this defined it will come from the indicated module'. Typically I use` imported\_from`, but this actually loads the dependency as a side-effect.

I chosen the `implementation_module/1` property over the `imported_from/1` property due to the latter side-effect (not that the side-effect itself is expected to be problematic as the main purpose of compiling modules as objects is to help in porting code).

---

<div class="post-metadata">

**Author:** ![pmoura](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/pmoura/32/11_2.png) [@pmoura](https://swi-prolog.discourse.group/u/pmoura)\
**Post date:** [November 15, 2019, 10:41am UTC](https://swi-prolog.discourse.group/t/finding-a-module-implicit-dependencies/1279/4 "2019-11-15T10:41:42Z")

</div>

> [@pmoura](#):
>
> I chosen the `implementation_module/1` property over the `imported_from/1` property due to the latter side-effect (not that the side-effect itself is expected to be problematic as the main purpose of compiling modules as objects is to help in porting code).

It turns out that the `implementation_module/1` property exists for **any** predicate, including non-existing ones. E.g.

```
?- predicate_property(just_invented(_,_), implementation_module(Module)).

Module = user.

```

This sounds like a bug and it makes the property useless in my use case. Thus, I’m switching to the `imported_from/1` property.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 15, 2019, 2:12pm UTC](https://swi-prolog.discourse.group/t/finding-a-module-implicit-dependencies/1279/5 "2019-11-15T14:12:07Z")

</div>

From the docs _“True when Module is the module in which Head **is or will be** defined”_ It is a rather tricky property that is needed for various tabling operations to get the right (qualified) call variant. It behaves as is intentionally for undefined predicates. You can of course first check that the predicate is defined.

---

<div class="post-metadata">

**Author:** ![pmoura](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/pmoura/32/11_2.png) [@pmoura](https://swi-prolog.discourse.group/u/pmoura)\
**Post date:** [November 15, 2019, 2:58pm UTC](https://swi-prolog.discourse.group/t/finding-a-module-implicit-dependencies/1279/6 "2019-11-15T14:58:57Z")

</div>

I did noticed that statement on the documentation before posting. But I also assumed that “will be defined” implied that a _declaration_ for the predicate (e.g. multifile, dynamic, or tabled) must exist beforehand.
