2

I would like to be able to retract and assert facts dynamically for the procedure location:

location(egg, duck_pen).

Based on advice online (including No permission to modify static procedure), I've tried adding each of the following to my source code, which otherwise contains only the above assertion:

dynamic location/2.
dynamic(location/2).
dynamic(location)/2.

The first two versions give me this error at compile-time (when loaded into SWI-Prolog):

No permission to redefine built-in predicate `(dynamic)/1'
Use :- redefine_system_predicate(+Head) if redefinition is intended

The last version does not give me an error at compile-time, but, whether I put it at the beginning or end of the file, I get an error when I try retracting my fact:

?- retract(location(egg,duck_pen)).
ERROR: retract/1: No permission to modify static procedure `location/2'

I am using SWI-Prolog version 6.6.5.

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Ellen Spertus
  • 6,576
  • 9
  • 50
  • 101

1 Answers1

1

Use

:- dynamic location/2.

location(X, Y) blah blah
Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Anniepoo
  • 2,152
  • 17
  • 17