Re: [eclipse-users] Reloading a file with dynamic predicates

From: Joachim Schimpf (Independent Contractor) <"Joachim>
Date: Wed, 18 Apr 2007 17:13:10 +0100
Paulo Moura wrote:
> Hi Kish!
>> For dynamic predicates, you can retract them before adding new  
>> ones. If you use retract_all/1,
>> you can remove all the definitions of the predicate:
>> ...
> That's not really a feasible solution. It would imply finding which  
> dynamic predicates are declared and which dynamic predicates are  
> defined in a file (before reloading it) in order to use, as you  
> suggest, retract_all/1 or abolish/1. It would be possible/easy to  
> modify the behavior of compile/1 to match the behavior of most Prolog  
> compilers when reloading a file? I.e. to "reset" the dynamic  
> predicates with the original file definitions, as already done for  
> static predicates?

Assigning such a significance to the *file* that a clause comes from
is really quite an irregular feature (clauses, especially dynamic ones,
don't always come from files, they may come from a socket, string, list,
tty, assert - what to do in these cases?).  It is a relic from the times
before there were module systems.

The problem doesn't exist with modules - when reloading a module, any
old module content gets erased, including dynamic predicates.

Another clean solution (in native ECLiPSe mode) is to put a :- dynamic
directive at the top of your file.  This will reinitialise the dynamic
predicate if it exists already.  Unfortunately, the ISO standard decided
to define dynamic/1 differently, so this isn't supported in lib(iso)
mode (which Paulo is probably using).  But, as Kish said, a portable
solution is to be explicit and add the reinitialisation to the dynamic
declaration, i.e.

:- dynamic p/1.
:- retract_all(p(_)).

-- Joachim
Received on Wed Apr 18 2007 - 17:13:23 CEST

This archive was generated by hypermail 2.3.0 : Thu Aug 22 2019 - 09:15:17 CEST