# Module name aliasing

**URL:** <https://swi-prolog.discourse.group/t/module-name-aliasing/2609>\
**Category:** General\
**Created:** [July 6, 2020, 7:40pm UTC](https://swi-prolog.discourse.group/t/module-name-aliasing/2609 "2020-07-06T19:40:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![emacstheviking](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emacstheviking/32/228_2.png) [@emacstheviking](https://swi-prolog.discourse.group/u/emacstheviking)\
**Post date:** [July 6, 2020, 7:40pm UTC](https://swi-prolog.discourse.group/t/module-name-aliasing/2609/1 "2020-07-06T19:40:38Z")

</div>

I am sure it can be done I swear I read it…–somewhere-- 😑

given the module `coder_base` that defines useful stuff, can I import it into another module as call it `cb` ??

I could create a new module that just re-exported everything but that feels fugly somehow.

Thanks,  
Sean.

---

<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:** [July 6, 2020, 7:54pm UTC](https://swi-prolog.discourse.group/t/module-name-aliasing/2609/2 "2020-07-06T19:54:40Z")

</div>

You can import a predicate using a different name. You cannot import a module using a different name. You can load a module into a different module than the one declared in its header using load\_files/2. What are you trying to do?

---

<div class="post-metadata">

**Author:** ![emacstheviking](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emacstheviking/32/228_2.png) [@emacstheviking](https://swi-prolog.discourse.group/u/emacstheviking)\
**Post date:** [July 6, 2020, 7:57pm UTC](https://swi-prolog.discourse.group/t/module-name-aliasing/2609/3 "2020-07-06T19:57:47Z")

</div>

just being lazy!

I have a bunch of stuff in a module called “coder\_base” and I was getting fed up typing coder\_base so I wondered if I could just `:-use_module(long_name, [as(ln)])` … the `as` of course being wish fulfilment at this point.

PENNY! Thanks Jan… I think I might need meta-predicate thing again where it knows to bind the module name to the call argument…except its not really an operator or did I misunderstand meta predicates !!!

---

<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:** [July 6, 2020, 8:13pm UTC](https://swi-prolog.discourse.group/t/module-name-aliasing/2609/4 "2020-07-06T20:13:56Z")

</div>

The module system is designed (by Quintus in the late 80s) such that it is an exception that you need to type or even know the module name. That still makes me wonder what you are trying to achieve 🙂

---

<div class="post-metadata">

**Author:** ![emacstheviking](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emacstheviking/32/228_2.png) [@emacstheviking](https://swi-prolog.discourse.group/u/emacstheviking)\
**Post date:** [July 6, 2020, 10:15pm UTC](https://swi-prolog.discourse.group/t/module-name-aliasing/2609/5 "2020-07-06T22:15:47Z")

</div>

Trying to achieve nothing really, I just wondered if it was possible. In Elixir for example you can say

```prolog
import Long.Module.Path as: LMP

```

and the in the code you can use

```prolog
LMP.foo()

```

I’ve realised I was being silly probably but it was just a thought that’s all.

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [July 7, 2020, 4:32am UTC](https://swi-prolog.discourse.group/t/module-name-aliasing/2609/6 "2020-07-07T04:32:55Z")

</div>

In prolog you normally type the module name only once, in the use\_module/1 directive; after that, you don’t have to type the module name, you just do:

```prolog
:- use_module(my_module).

pred(Args) :-
   some_pred_in_my_module(Args).

```

---

<div class="post-metadata">

**Author:** ![emacstheviking](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/emacstheviking/32/228_2.png) [@emacstheviking](https://swi-prolog.discourse.group/u/emacstheviking)\
**Post date:** [July 7, 2020, 12:00pm UTC](https://swi-prolog.discourse.group/t/module-name-aliasing/2609/7 "2020-07-07T12:00:11Z")

</div>

Yes, but the predicate I am calling is returning a “promise” to be executed later.  
It returns, in the spirit of `print_message/2` a list of pairs of format strings and arguments, for example:

```prolog
if_then(..., Out ) :-
   ...
   Out = ['if (~s) {\n'-[CondStr],
          indent(IfBodyStr), nl, '}',
          % this line added to demonstrate my problem
          '~@'-[coder_base:csv(ListOfThings)]
         ]

```

The problem is that I have to qualify the call to coder\_base:csv because when this code executes I am no longer in this module but in my “render” module…so it’s like the meta predicate thing where you can tell the compiler to maintain the module name as part of the call site information.

Not a problem…moved on with it since.
