From jan@swi.psy.uva.nl Tue Oct  2 16:15:41 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f92EFfv06143;
	Tue, 2 Oct 2001 16:15:41 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.3/8.11.3/SuSE Linux 8.11.1-0.5) id f92EFfY01681;
	Tue, 2 Oct 2001 16:15:41 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Armando Stellato <starred@tiscalinet.it>,
   SWI Mailing List <prolog@swi.psy.uva.nl>
Subject: Re: [SWIPL] module coerency problem
Date: Tue, 2 Oct 2001 16:13:15 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <3BB9B22D.5090104@tiscalinet.it>
In-Reply-To: <3BB9B22D.5090104@tiscalinet.it>
MIME-Version: 1.0
Message-Id: <01100216154100.00929@gollem>
Content-Transfer-Encoding: 8bit

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

