# Reusing predicate name across modules

**URL:** <https://swi-prolog.discourse.group/t/reusing-predicate-name-across-modules/7181>\
**Category:** General\
**Tags:** module\
**Created:** [January 20, 2024, 6:38pm UTC](https://swi-prolog.discourse.group/t/reusing-predicate-name-across-modules/7181 "2024-01-20T18:38:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![viridium](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@viridium](https://swi-prolog.discourse.group/u/viridium)\
**Post date:** [January 20, 2024, 6:38pm UTC](https://swi-prolog.discourse.group/t/reusing-predicate-name-across-modules/7181/1 "2024-01-20T18:38:08Z")

</div>

With use\_module/1, it’s possible to refer to the imported predicates using the module name as prefix, as in `module_name:predicate`. This implies that I should be able to reuse predicate names across modules without clashes. However, that is not what I am seeing.

How can I import predicates from both modules without running into the error below? In theory, the two predicates can be referenced as `m1:hello` and `m2:hello`, and there needn’t be a name clash as long as we don’t try using the unqualified name.

Why it’s important to be able to reuse predicate names across modules: because that’s the promise of modules as I understand it. Otherwise, I can just do without modules and manage my predicate names manually across the entire program.

```prolog
% m1.pl
:- module(m1, [hello/0]).
hello :- writeln('hello from m1').

% m2.pl
:- module(m2, [hello/0]).
hello :- writeln('hello from m2').

% m3.pl
:- module(m3, []).
:- use_module(m1).
:- use_module(m2).
run :- m1:hello.

```

This gives an error:

```prolog
ERROR: m3.pl:3:
ERROR: import/1: No permission to import m2:hello/0 into m3 (already imported from m1)

```

---

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [January 20, 2024, 8:52pm UTC](https://swi-prolog.discourse.group/t/reusing-predicate-name-across-modules/7181/2 "2024-01-20T20:52:05Z")

</div>

I believe that error is happening because use\_module/1 implicitly puts all the exported predicates into the importing modules. If you use use\_module/2 with an empty import list, then it should work as intended.

```prolog
:- module(m3, []).
:- use_module(m1, []).
:- use_module(m2, []).
run :- m1:hello.

```

---

<div class="post-metadata">

**Author:** ![viridium](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@viridium](https://swi-prolog.discourse.group/u/viridium)\
**Post date:** [January 21, 2024, 2:37am UTC](https://swi-prolog.discourse.group/t/reusing-predicate-name-across-modules/7181/3 "2024-01-21T02:37:44Z")

</div>

Amazing, thank you!
