Questions tagged [prolog-assert]

Prolog-assert globally affects stored information in Prolog, a general purpose logic programming language.

Source: http://alumni.cs.ucr.edu/~vladimir/cs171/prolog_2.pdf

Prolog assert(X) Adds a new fact or clause to the database. Term is asserted as the last fact or clause with the same key predicate.

47 questions
27
votes
1 answer

Prolog - ASSERT and RETRACT

I was wondering, I am aware you can use assert to add facts or rules or whatever if you have declared the predicate to be -:dynamic, but this only allows the changes that are made to be kept in that session only, e.g. if you close the Prolog window…
KP65
  • 13,315
  • 13
  • 45
  • 46
10
votes
3 answers

Prolog - how to clear the memory and start from scratch?

I'm developing an algorithm in a .pl file, and examining it with queries on the command window. I use dynamic variables and retract/assert predicates. And when I modify the pl file and click on "reload modified files", I have extra facts that I…
void
  • 1,876
  • 8
  • 24
  • 30
10
votes
3 answers

What is the difference between abolish/1 and retractall/1?

From reading the manual, I can't seem to find the difference between the two. The manual says: It is advised to use retractall/1 for erasing all clauses of a dynamic predicate. So I chose to use retractall/1 in my program; however, I wonder what…
Kevin Van Ryckegem
  • 1,915
  • 3
  • 28
  • 55
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
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
7
votes
2 answers

Defining predicates in SICStus Prolog / SWI-Prolog REPL

I am reading http://cs.union.edu/~striegnk/learn-prolog-now/html/node3.html#subsec.l1.kb1, but I am having trouble running the following predicate: SICStus 4.0.1 (x86-win32-nt-4): Tue May 15 21:17:49 WEST 2007 | ?- woman(mia). ! Existence error in…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
7
votes
1 answer

GNU Prolog assert error

I am new to Prolog, but I am stuck at this supposedly simple command. I have loaded a knowledge base with no errors, and whenever I try do assert (and even help) I get the following message: uncaught exception:…
zpavlinovic
  • 1,507
  • 1
  • 17
  • 36
6
votes
2 answers

How to avoid using assert and retractall in Prolog to implement global (or state) variables

I often end up writing code in Prolog which involves some arithmetic calculation (or state information important throughout the program), by means of first obtaining the value stored in a predicate, then recalculating the value and finally storing…
5
votes
2 answers

How Prolog's logical update view works for assert and retract?

Can someone please explain the Prolog logical view about assert and retract in details? For example in code below, in the first run Prolog returns true and in subsequent runs returns false. I don't know why because of Prolog logical view when …
CoderInNetwork
  • 2,923
  • 4
  • 22
  • 39
5
votes
2 answers

SWI-Prolog - Fail to Assert

I define an operator as follows: :- op(500, xfx, =>). When I try something like: assert(a => b). Prolog raises an error that says 'No permission to modify static_procedure (=>)/2'. Any solution?
mrk
  • 3,061
  • 1
  • 29
  • 34
4
votes
4 answers

How to use dynamic databases in Prolog?

I have written the following program, which calculates the longest non-decreasing sub-sequence of input array. The sub-program to find the longest list from the list of lists is taken from stackoverflow (How do I find the longest list in a list of…
UnSat
  • 1,347
  • 2
  • 14
  • 28
4
votes
2 answers

Prolog: Different behaviour of single and double quotes

I'm quite new to Prolog and I stumbled on something that I don't understand. This is my code: :- dynamic user/3. user('id', 'Name', 20). changeAge(Id, NewAge) :- user(Id, Name, _), retract(user(Id,_,_)), assert(user(Id,Name,NewAge)). To…
Ionut
  • 1,729
  • 4
  • 23
  • 50
3
votes
1 answer

Asserting and retracting to emulate global variables

I'm doing this to emulate global variables: update_queue(NewItem) :- global_queue(Q), retractall(global_queue(Q)), append(Q, [NewItem], NewQ), assert(global_queue(NewQ)). Is there another way? (Besides passing the variables as…
3
votes
2 answers

Dynamic Prolog predicate with incrementing component

I have a knowledge base consisting of a set of rules whose head of each rule performs assert or retract of complex terms when certain conditions occur. How can I ensure that Id is incremented with each assert(term(Id,A,B,C))?
3
votes
2 answers

Unable to create Fact in Jekejeke Prolog

I'm using the Seven Languages In Seven Weeks Prolog tutorial and trying to run through some examples using the Android Jekejeke Runtime. For example, if I add likes(wallace, grommit). from the tutorial, I get. Error: Undefined, private or package…
matt freake
  • 4,877
  • 4
  • 27
  • 56
1
2 3 4