Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining a module in Prolog

Tags:

module

prolog

I have some problems defining a module. Here's a short reduction of the code:

:- module(my_module, [word/1]).
:- module(my_module, [alias_of/2]).

alias_of(A, B) :-
        alias_of(A, C),
        alias_of(C, B).
alias_of('Word_1', 'Word_2').

word(A) :-
        alias_of(B, A),
        word(B).
word('Word_1').
word('Word_3').

And this is the SWI-Prolog output when I consult the file:

1 ?- ERROR: (i:/dev/prolog-workspace/trial.0.pro:2):
        Undefined procedure: my_module:module/2
            However, there are definitions for:
                module/1
Warning: (i:/dev/prolog-workspace/trial.0.pro:2):
        Goal (directive) failed: my_module:module(my_module, [alias_of/2])

I thought, from the tutorials I read, that exposing predicates could be done using :- module(module_name,[predicate_name/arity]). What's wrong ?

EDIT: as I have played with this code now and tested it as a module, I figured out it's completely bugged...

like image 269
Stephane Rolland Avatar asked Nov 19 '25 04:11

Stephane Rolland


1 Answers

module must be the first directive, and must appear just once.

:- module(my_module, [word/1, alias_of/2]).
... etc...
like image 51
CapelliC Avatar answered Nov 22 '25 04:11

CapelliC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!