Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"dynamic" predicate in prolog

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?

like image 801
KP65 Avatar asked Mar 11 '10 16:03

KP65


People also ask

What is a dynamic predicate in Prolog?

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].

What is dynamic database in Prolog?

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.

Is Prolog dynamic or static?

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.

Is Prolog a predicate?

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.


1 Answers

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;
like image 148
Jeff Dallien Avatar answered Nov 19 '22 16:11

Jeff Dallien