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

From: Kish Shen <kish_at_...2...>
Date: Mon, 16 Apr 2007 02:09:45 +0100
Paulo Moura wrote:
> Hi!
>
> In ECLiPSe, reloading a file containing dynamic directives and  
> dynamic predicates fails to restore the original definitions from the  
> file. E.g. if the file contains a single clause for a dynamic  
> predicate, simply reloading it results in two clauses in memory.  
> Reloading it a second time, results in three repeated clauses and so  
> on. This is the documented behavior of the compile/1:
>
> "(...) static procedures are redefined by those occurring in the  
> compiled file, the clauses of dynamic procedures are appended to the  
> existing ones."
>
> Is there any solution to replace the clauses of dynamic predicates  
> instead of appending them?
>
> Best regards,
>
> Paulo
>
>
> -----------------------------------------------------------------
> Paulo Jorge Lopes de Moura
> Dep. of Computer Science, University of Beira Interior
> 6201-001 Covilhã, Portugal
>
> Office 4.3  Ext. 3257
> Phone: +351 275319891 Fax: +351 275319899
> Email: <mailto:pmoura_at_...16...>
>
> Home page: <http://www.di.ubi.pt/~pmoura>
> Research: <http://logtalk.org/>
> -----------------------------------------------------------------
>
>
>
>
> _______________________________________________
> ECLiPSe-Users mailing list
> ECLiPSe-Users_at_...2...
> http://www.crosscoreop.com/mailman/listinfo/eclipse-users
>   
Hi Paulo,

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:

[eclipse 6]: [user].
 :- dynamic foo/1.
 foo(a).
 foo(b).
 foo(c).
 user       compiled traceable 36 bytes in 0.00 seconds

Yes (0.00s cpu)
[eclipse 7]: foo(X).

X = a
Yes (0.00s cpu, solution 1, maybe more) ? ;

X = b
Yes (0.00s cpu, solution 2, maybe more) ? ;

X = c
Yes (0.00s cpu, solution 3)

[eclipse 9]: retract_all(foo(_)).

Yes (0.00s cpu)
[eclipse 10]: foo(X).

No (0.00s cpu)

and you can now add new clauses:

[eclipse 11]: [user].
 foo(e).
 foo(f).
 user       compiled traceable 16 bytes in 0.00 seconds

Yes (0.00s cpu)
[eclipse 12]: foo(X).

X = e
Yes (0.00s cpu, solution 1, maybe more) ? ;

X = f
Yes (0.00s cpu, solution 2)


You can also use abolish/1 to remove the definitions of predicates. See 
the predicate description for more details.

Cheers,

Kish
Received on Mon Apr 16 2007 - 02:10:05 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:19 CEST