"dynamic" predicate in prolog

25.4k Views Asked by At

If I want to make a rule dynamic so i can use assert after the database file has been loaded, how do i do it? I'm using XSB Prolog at the moment, the file is something like this:

:- dynamic likes/2

likes(mary,tom)

when i try to consult the file with XSB i get an error:

? consult('D:\file.P).
not permitted to assert to static predicatelikes/2
forward continuation...blahblah

Any ideas?

1

There are 1 best solutions below

3
Jeff Dallien On BEST ANSWER

The dynamic predicate works as you are expecting, so there is something else wrong if it is not working for you.

If test.P looks like this:

:- dynamic likes/2.

likes(mary,tom).

It can be consulted, and then more likes/2 facts can be asserted:

XSB Version 3.2 (Kopi Lewak) of March 15, 2009
[i686-pc-linux-gnu; mode: optimal; engine: slg-wam; scheduling: local; word size: 32]

| ?- consult('test.P').
[Compiling ./test]
[test compiled, cpu time used: 0.0440 seconds]
[test loaded]

yes
| ?- assert(likes(mary, bob)).

yes
| ?- likes(X,Y).

X = mary
Y = tom;

X = mary
Y = bob;