# Abbreviated module names

**URL:** <https://swi-prolog.discourse.group/t/abbreviated-module-names/7431>\
**Category:** Help!\
**Tags:** how-to\
**Created:** [May 2, 2024, 12:42pm UTC](https://swi-prolog.discourse.group/t/abbreviated-module-names/7431 "2024-05-02T12:42:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![twan](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@twan](https://swi-prolog.discourse.group/u/twan)\
**Post date:** [May 2, 2024, 12:42pm UTC](https://swi-prolog.discourse.group/t/abbreviated-module-names/7431/1 "2024-05-02T12:42:16Z")

</div>

I’m using: SWI-Prolog version 8.2.4 on MacOS 14

I was wondering whether it is possible to abbreviate the imported module _name when_ using its exported predicates.

Python and Java have this possibility:

```python
import alibrary as al

```

```java
import com.twan.metamodel as mm;

```

To illustrate: Say I’ve in my module the following directive (the Prolog fragments in the example are taken from my current project)

```prolog
:- module(metamodel, [relationship/3, entity/2, property/3, ...]).
...

```

And use that as follows in another module:

```prolog
:- module(application, [...]).

:- use_module(library(metamodel)).

metamodel:entity(......)
metamodel:relationship( ....)
...

```

But rather than writing `metamodel:entity` or `metamodel:relationship`, I’ld like to be able to write `mm:entity` and `mm:relationship`.

Is there a mechanisme in SWI Prolog facilitating this?

For now, thanks for reading!

/Twan

---

<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:** [May 2, 2024, 1:10pm UTC](https://swi-prolog.discourse.group/t/abbreviated-module-names/7431/2 "2024-05-02T13:10:01Z")

</div>

It should be in the FAQ (which I am updating as we speak). The SWI-Prolog module system works differently. This applies to all Prolog systems who’s module system is based on Quintus Prolog’s module system designed in the late 80s.

In Python (and many modern languages), an import just makes the module available and you have to access the functions as `module.func()` or something similar. In Prolog, importing a module adds the predicates of the module to the current name space. So, after importing the `metamodel`, you can access its predicates as

```
entity(...).

```

To make this usable, use\_module/2 allows you to import only the predicates you really use and it also allows for renaming, e.g.

```
:- use_module(metamodel, [entity/1 as ent]).

t :- ent(X).

```

The `as name` is a SWI-Prolog extension also seen in some other systems. The “classical” deal with a conflict is to use use\_module/2, not importing the conflicting predicate from multiple places and use `module:pred(....)` to make the calls.

The normal way to deal with this is

- Use long unique module names in the `:- module(...)` declaration.
- Use somewhat longer names for exported predicates. In many cases the exported predicates have some abbreviation of the library name as part of their name. See the system libraries for many (mostly good, some dubious) examples.
