Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring a predicate dynamic in gprolog

I have this code in Prolog:

dynamic(player_at/1).
player_at(house).
goto(X) :- retract(player_at(house)), assert(player_at(X)).

But I still get this error:

uncaught exception: error(permission_error(modify,static_procedure,player_at/1),retract/1)

when I execute goto(foo).

I've read the dynamic documentation, but I can't figure out how to use it, at least in gprolog. Am I missing something?

like image 958
Kai Avatar asked May 09 '09 20:05

Kai


1 Answers

Fix the first line by prepending :-:

:- dynamic(player_at/1).

Without :- the line would dreefine predicate dynamic/1, instead of executing the existing dynamic predicate.

Other prolog implementations (but not gprolog) support this as well:

:- dynamic player_at/1.
like image 50
pts Avatar answered Nov 03 '22 11:11

pts