Questions tagged [prolog-directive-dynamic]

The directive `dynamic/1` specifies that certain user-defined predicates are dynamic which are given as predicate indicators, either as in a list, in an and-sequence, or a single predicate indicator.

References:

SWI-Prolog
How to deal with the Prolog dynamic database?
Database

22 questions
8
votes
1 answer

Can I use variables with assert/1?

What I have now checks that X(Y) is not an accepted fact in my small DB. Since X(Y) returns false it will attempt to assert it. (I realize this presents problems when X is a rule and not a fact) ifNotAdd(X,Y):- not(call(X,Y)), !, …
Carson Wilcox
  • 351
  • 1
  • 2
  • 8
8
votes
1 answer

Declaring a predicate dynamic in gprolog

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:…
Kai
  • 3,997
  • 4
  • 30
  • 36
7
votes
1 answer

I want to create dynamic facts in prolog

I wrote the following simple code, and I expect that when I write 'male.', this code ask me once "is it male?" and if i input 'No' it write on screen "she is female". male :- ( print('is it male ? '),read(yes)) -> true; asserta(…
vakarami
  • 576
  • 9
  • 22
6
votes
1 answer

Predicate cache

Is there a Prolog implementation or library that caches predicates? Or would you implement a, say, FIFO cache using assertz/1 and retract/1, like this: :- dynamic cache/1. ccall(G) :- cache(G). ccall(G) :- \+ cache(G), call(G), (…
chs
  • 652
  • 4
  • 17
6
votes
3 answers

Efficient Mutable Graph Representation in Prolog?

I would like to represent a mutable graph in Prolog in an efficient manner. I will searching for subsets in the graph and replacing them with other subsets. I've managed to get something working using the database as my 'graph storage'. For…
6
votes
1 answer

"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…
KP65
  • 13,315
  • 13
  • 45
  • 46
6
votes
2 answers

What does a clause without a head mean in prolog?

In the beginning of a Prolog program I see: :-dynamic(path/1). It seems to be a clause that doesn't have a head. What does it mean?
hpn
  • 2,222
  • 2
  • 16
  • 23
3
votes
2 answers

current_predicate/1 does not work with :- dynamic?

I have some predicates that I define using asserts in Prolog. I am using current_predicate/1 in order to know whether the assert has been run or not (only one value needs to be asserted). However, swipl keeps complaining: Warning: The predicates…
Kevin Van Ryckegem
  • 1,915
  • 3
  • 28
  • 55
2
votes
1 answer

Prolog - Reduce the knowledge base by deduction

I need to create a rule that will search for the facts that matches my_rule. These facts will be use to change the knowledge base. (my_rule (Conclusion, Premise)). I have this knowledge base to start with : :- dynamic( is/2 ). is( m1, house ). is(…
Vini
  • 116
  • 1
  • 7
2
votes
1 answer

Asserting and using fast, LARGE arrays in prolog

I'm using functors to get random-access arrays using arg/3 in SWI-Prolog. What i'm doing is loading values from a sample into a functor I create and asserting the array for future use. Once loaded, Random access is indeed O(1) as I've verified using…
2bigpigs
  • 452
  • 3
  • 12
2
votes
1 answer

Modules with dynamic predicates

This is a follow up question to : Adapting csv reading for multiple tables If I have the following module defined: :- module(csv_load_mod,[prepare_db/3]). :- use_module(library(csv)). :- set_prolog_stack(global, limit(4*10**9)). prepare_db(File,…
2
votes
1 answer

Unable to make facts dynamic in SWI-Prolog

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…
Ellen Spertus
  • 6,576
  • 9
  • 50
  • 101
2
votes
1 answer

SWI-Prolog dynamic/1 vs dynamic/2

I am teaching myself Prolog and have been given a handful of examples. One of which uses the dynamic/1 built-in directive: :- dynamic(items/1). I get the idea of dynamic. That one can modify predicates via the assert, and retract…
Andrew S
  • 2,847
  • 3
  • 33
  • 50
1
vote
1 answer

Use dynamic/1 and var/1 Create Prolog clauses that allow the following

?- say([the, capital, of, switzerland, is, bern]). Thank you. ?- say([the, capital, of, switzerland, is, bern]). I already know that. ?- say([the, capital, of, switzerland, is, zurich]). No, you said the capital of switzerland is bern. ?-…
Xueqi Zhao
  • 25
  • 4
1
vote
1 answer

Prolog - Consult actually cleans current state?

I had the following code for customer creation and listing: :-dynamic customer/2. load:-consult('C:\\customers.txt'). save:-tell('C:\\customers.txt'), listing(customer), told. %New customer new_customer:-write("Name: "), read(Name),…
Alvaro
  • 11,797
  • 9
  • 40
  • 57
1
2