Subject: Re: [SWIPL] module coerency problem

From: Armando Stellato <[email-masked]>
Date: Tue, 02 Oct 2001 18:17:55 +0200

Thanks Jan, multifile is exactly what I needed, it is written clearly in 
the manual, but i didn't remember even its existence.
However this is good if i decide to make "agents_io" consult the module 
with other handle_msg definitions (let us call it "extended_module").
On the other hand, If i decide to make "agents_io" use_module (and not 
consult directly) "extended_module", and make handle_msg in 
"extended_module" public, i continue to receive:
ERROR: (i:/tesidilaurea/myworkspace/coordinator_agent.pl:17):
Cannot import coordinator_agent:handle_msg/2 into module agents_io:
name clash

is it possible to solve this problem also when using use_module instead 
of consult?
Thank you again
Armando

Jan Wielemaker wrote:

> On Tue, 02 Oct 2001, Armando Stellato wrote:
> 
>>Hi, I've a problem with modules:
>>I'm building an agent environment.
>>I'm making great use of modules, so to create various layers and be able 
>>to work on each of them without modify the code in the substrates.
>>
>>I've a module named agents who use_module various modules, every agent 
>>written uses only imported methods (predicates) from module:agents, then 
>>'agents' calls methods from its various submodules who are visible only 
>>by himself.
>>
>>The problem is:
>>One of the submodules is agents_io that has a method called: handle_msg/2.
>>I would like to expand agents_io with conditional consulting/use_module 
>>with new instances of handle_msg/2.
>>I'll make an example:
>>in 'agents_io' i've:
>>handle_msg(AgentId,txt_msg(TXT)),
>>handle_msg(AgentId,disconnect).
>>
>>I've build a module called 'coordinator_agent' that is consulted only if 
>>the agent using module agent is of type:coordinator.
>>This module is consulted by "agents_io" and should give some more 
>>handle_msg methods.
>>Exampe:
>>exp_handle_msg(AgentId,agent_declare(ROLE,ONTOLOGY,LANGUAGE))
>>
>>The problem is:
>>if i make agents_io consult 'coordinator_agent', the compiler says me 
>>that i've redefined handle_msg/2, so it doesn't uses original handle:msg 
>>
>>from agents_io
> 
>>if i make agents_io use_module coordinator_agent (rewritten as a 
>>module), the compiler says me that predicate names clash (cause 
>>handle_msg is already defined in agents_io).
>>
>>Is there really no way to add some more handle_msg predicates to 
>>agents_io, without modifying everytime the code in the module agents_io???
>>I don't want to go around the problem using another name for the 
>>predicates handle_msg in coordinator_agent and invoke them if handle_msg 
>>fails on agents_io. This is a solution but i don't like it, it is "dirty".
>>any other solution?
>>
> 
> Not sure I've understood the whole story, but I think the key to your
> problem is the :- multifile some_module:agents_io/2.  According to the
> standard, this directive should be above the clauses in all files
> defining clauses for this predicate.  SWI-Prolog currently doesn't
> enforce this.
> 
> 	Regards --- Jan
> 
>