Module name aliasing

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

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.

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?

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 !!!

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 :slight_smile:

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

import Long.Module.Path as: LMP

and the in the code you can use

LMP.foo()

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

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:

:- use_module(my_module).

pred(Args) :-
   some_pred_in_my_module(Args).
1 Like

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:

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.