Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!gatech!swrinde!pipex!sunic!sunic.sunet.se!news.lth.se!news.lu.se!venus.ling.lu.se!user
From: Johan.Dahl@ling.lu.se (Johan Dahl)
Subject: Re: help with SICStus Prolog and retract/1
Message-ID: <Johan.Dahl-2004951614570001@venus.ling.lu.se>
Sender: news@nomina.lu.se (USENET News System)
Nntp-Posting-Host: venus.ling.lu.se
Organization: Lingvistics & Phonetics, Univ. of Lund, Sweden
References: <3n1d38$ef9@lectura.CS.Arizona.EDU>
Date: Thu, 20 Apr 1995 14:14:57 GMT
Lines: 68

In article <3n1d38$ef9@lectura.CS.Arizona.EDU>, dave@CS.Arizona.EDU (Dave
Schaumann) wrote:

> The short story is this: I want to establish a fact in a file, load it
> into (SICStus) Prolog using consult/1, and then later retract it.
> 
> However, SICStus Prolog doesn't let me:
> 
> #> cat foo
> #foo(bar).
> #> prolog
> #SICStus 2.1 #9: Tue Aug 23 17:38:08 MST 1994
> #| ?- consult(foo).
> #{consulting foo...}
> #{foo consulted, 16 msec 336 bytes}
> #
> #yes
> #| ?- retract(foo(bar)).
> #{PERMISSION ERROR: retract(user:foo(bar)) - cannot retract static user:foo/1}
> #| ?- 
> 
> Is there a way around this?
> 
> Thanks...
> 
> -Dave


Hi

You have to declare all consulted predicates to be dynamic if you are
going to do retract and assert on them. Otherwise they are considered
static. This distinction is made to 1) protect the program. If you try to
assert or retract something what was not ment to, it's an error. 2) Allow
compilers to optimize on code which do not change.


So to do this you include the operator dynamic in the file you consult.
Here is a little file foo.pl:

---- foo.pl------

:- dynamic foo/1. %% foo with arity 1 (one argument)

foo(bar).
foo(fum).

--- end of foo.pl-----

?- consult('foo.pl').

OK or whatever....
?- retract(foo(X)).

X = bar

?- assert(foo(hum)).
OK

Hope this helps
If you have further questions you can send me an email

         Johan Dahl
-- 
Johan Dahl Johan.Dahl@ling.lu.se
Department of Lingvistics and Phonetics
University of Lund
Sweden
