8

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?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Kai
  • 3,997
  • 4
  • 30
  • 36
  • Eventually you should get already an exception during the consult of your program. It should not allow a dynamic(_) fact. The ISO standard only says that dynamic is a directive, but in most Prologs it is also a built-in, and can thus not be asserted as a fact. –  Jul 19 '11 at 10:41

1 Answers1

14

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.
pts
  • 80,836
  • 20
  • 110
  • 183
  • I tried that - I get syntax error: . or operator expected after expression. It doesn't like the dynamic without a parenthesis. – Kai May 09 '09 at 21:04