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?
Predicates that are unknown are implicitly defined as dynamic when they appear first-time in: asserta/1, asserta/2, assertz/1, assertz/2, retract/2, retractall/1. Examples: Use predicate like a dynamic predicate, but the predicate was previously used non-dynamically: NO ?- [user].
Dynamic database can change dynamically at execution time and are of two types. Type1: created at each execution. It grows, shrinks and is deleted at the end of program. ● This type of database is no longer available after program finishes its execution and is called working memory.
In Prolog, a procedure is either static or dynamic. A static procedure is one whose facts/rules are predefined at the start of execution, and do not change during execution. Normally, the facts/rules will be in a file of Prolog code which will be loaded during the Prolog session.
Prolog predicate is the method to contain the argument and return the boolean values such as true or false. It is a function to operate and return given values, variables, or arguments using a prolog programming language.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With