funcount(1).
newfuncount(N) :-
funcount(N),
retract(funcount(N)),
M is N + 1,
assert(funcount(M)).
reset :-
retract(funcount(_)),
assert(funcount(1)),
!.
But, when I actually call reset or newfuncount,
SWI-Prolog has a ERROR message:
ERROR: No permission to modify static procedure "funcount/1".
Could anyone tell me how to avoid this problem? Thanks
Yours
Qiong
You probably have to declare funcount/1 as dynamic before any use
of it. You certainly have to use a directive or a build-in predicate
for that, putting
:- dynamic funcount/1 .
at top of your program.
HTH
--
Pascal
Defining it dynamic will probably work though I'm not really sure about it.
The problem you're facing didn't appear in the pre-ISO-prolog versions of
SWI prolog so it's probably forced by the ISO definitions.
Why it occurs is that with writing funcount(1) you statically (in your
programcode) define something. Asserting is done dynamically. If defining it
dynamic doesn't work you can always remove funcount(1) and make an procedure
that does nothing but asserting funcount(1). So make a procedure like
initialize :-
assert(funcount(1))
BTW. what does this program do? It seems to be only a snippet of a larger
example.
Casper Kuijjer
http://www.science.uva.nl/~ckuijjer
It's a help predicate in a theorem prover for first-order logic using
tableau
method.
Thanks
Qiong
"Casper Kuijjer" <ckui...@wins.uva.nl> wrote in message
news:9f7k5e$gb5$1...@news1.xs4all.nl...
>
>"Qiong Cai" <qio...@cse.unsw.edu.au> wrote in message
>news:3b1728e...@nancy.pacific.net.au...
>> Hi all,
>> Some codes from the book "First-Order logic
>> and Automated Theorem proving"(2nd) are as follows:
>>
>> funcount(1).
>>
>> newfuncount(N) :-
>> funcount(N),
>> retract(funcount(N)),
>> M is N + 1,
>> assert(funcount(M)).
>>
>> reset :-
>> retract(funcount(_)),
>> assert(funcount(1)),
>> !.
>>
>> But, when I actually call reset or newfuncount,
>> SWI-Prolog has a ERROR message:
>> ERROR: No permission to modify static procedure "funcount/1".
>
>Defining it dynamic will probably work though I'm not really sure about it.
>The problem you're facing didn't appear in the pre-ISO-prolog versions of
>SWI prolog so it's probably forced by the ISO definitions.
>
It seems like dynanic should be the default to me. Another
politically incorrect way to delete something is with the "abolish"
predicate.
>"Casper Kuijjer" <ckui...@wins.uva.nl> wrote:
>
>>Defining it dynamic will probably work though I'm not really sure about it.
>>The problem you're facing didn't appear in the pre-ISO-prolog versions of
>>SWI prolog so it's probably forced by the ISO definitions.
>
>It seems like dynanic should be the default to me.
Making procedures `dynamic' by default would lead to less efficient code.
The ISO standard allows implementations to make procedures static by default,
but IIRC does not require it.
--
Fergus Henderson <f...@cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
>jazzbox writes:
>
>>"Casper Kuijjer" <ckui...@wins.uva.nl> wrote:
>>
>>>Defining it dynamic will probably work though I'm not really sure about it.
>>>The problem you're facing didn't appear in the pre-ISO-prolog versions of
>>>SWI prolog so it's probably forced by the ISO definitions.
>>
>>It seems like dynanic should be the default to me.
>
>Making procedures `dynamic' by default would lead to less efficient code.
>
>The ISO standard allows implementations to make procedures static by default,
>but IIRC does not require it.
I guess I'd still put in my vote for dynamic-default. I had the same
problem at first as the original poster. Anyway, the standard
approach to inefficient code these days seems to be just buy a faster
computer.
Mike
>On 3 Jun 2001 16:56:29 GMT, f...@cs.mu.oz.au (Fergus Henderson) wrote:
>
>>jazzbox writes:
>>
>>>"Casper Kuijjer" <ckui...@wins.uva.nl> wrote:
>>>
>>>>Defining it dynamic will probably work though I'm not really sure about it.
>>>>The problem you're facing didn't appear in the pre-ISO-prolog versions of
>>>>SWI prolog so it's probably forced by the ISO definitions.
>>>
>>>It seems like dynanic should be the default to me.
>>
>>Making procedures `dynamic' by default would lead to less efficient code.
>>
>>The ISO standard allows implementations to make procedures static by default,
>>but IIRC does not require it.
>
>I guess I'd still put in my vote for dynamic-default. I had the same
>problem at first as the original poster.
assert/1 and retract/1 should be better documented, then.
Part of the problem is that a lot of the Prolog documentation,
textbooks, etc., predate the ISO Prolog standard.
Making things dynamic by default would have a *major* impact on efficiency
for optimizing compilers.