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
0
votes
0 answers

In Prolog, What are some reasons assert and retract could cause the query to fail?

I am applying the Logic De Morgan rule to all nodes of a set. Whenever I assert/retract the nodes matching the specified format, the query seems to stop there and return no. While this doesn't cause problems for applying the De Morgan rule once, it…
0
votes
3 answers

Prolog - stop repeat when last fact

I have a list of facts like this: set(h, 3). set(h, 6). set(h, 12). set(h, 1). set(h, 7). I need to find the maximum value of set h and the query needs to look like this: ?- maximum(h, Max). Max = 12. Now there are many ways to do this, obviously.…
PadaKatel
  • 177
  • 2
  • 15
0
votes
2 answers

Consulting an atom

One can easily consult a Prolog file using consult/1 or [filename].. Suppose I generate Prolog code as an atom. I can in a predicate write that code to a file and then consult it, and query a predicate from that code, e.g. example :- …
Fatalize
  • 3,513
  • 15
  • 25
0
votes
1 answer

PROLOG retract its not working

I need to delete an item from a list of predicates, but it's not working. It returns true for me yet the item is still there. Code: eliminar :- limpar, write('\n*** DELETAR ***\n'), write('O que deseja deletar ?\n'), pegarString(X), …
martur94
  • 111
  • 10
0
votes
1 answer

How can I call a function random inside other function in prolog?

I'm trying to call the random function inside another function. For example I want to do this assert(fact(random()). But it does not work. How can I insert a random number this way? Thanks.
Kim Doe
  • 3
  • 1
  • 11
0
votes
1 answer

Appending facts into an existing prolog file

I'm having trouble inserting facts into an existing Prolog file, without overwriting the original contents. Suppose I have a file test.pl: :- dynamic born/2. born(john,london). born(tim,manchester). If I load this in prolog, and I assert more…
vuj
  • 15
  • 1
  • 3
0
votes
1 answer

Read csv file from prolog and change to facts/clause

I use csv_read_file to read a csv file, which is: csv file: "nsubj(love-1, carol-2)" "nsubj(like-3, carol-2)" code: csv_read_file('test.csv',L) I got things like: L = [row('nsubj(love-1, carol-2)'), row('nsubj(like-3, carol-2)')] But what I need…
ba9el
  • 28
  • 4
0
votes
0 answers

Adding clause in Prolog

I am about to write code for my project, which is to create a database in SWI-Prolog. The program should contain ADDING, DELETING, SORTING and SEARCHING entries. My problems are: I want to ADD 'runners' with capital letters. When I'm addin/deleting…
0
votes
1 answer

Prolog - Using dynamic with asserts

I'm new to Prolog and I'm having a hard time using a dynamic predicate. First, here's the code I'm executing :- dynamic(list/1). add(X, LL) :- asserta(list([])), asserta(list(X)), retract(list(LL)). I know the code looks weird, but I'm simply…
0
votes
0 answers

Calling a procedure during assert in Prolog

I have an assert query that is something like: :- dynamic a/1,b/1. dump:- listing(a),listing(b). main:-retractall(a(X)),assert(a(1):-write('aa')), retractall(b(X)),assert(b(1):-write('bb')). I want the user to type a(1) or b(1), the program…
Shevliaskovic
  • 1,562
  • 4
  • 26
  • 43
0
votes
1 answer

Prolog assert/retract not working (?)

I try to create a simple program in prolog, but i have a problem: :- dynamic at/2, i_am_holding/1, i_am_at/1. /* some lines of code */ i_am_at(room1). at(revolver, room1). take(revolver) :- write('You picked up the revolver.'),nl. take(X):-…
Shevliaskovic
  • 1,562
  • 4
  • 26
  • 43
0
votes
1 answer

Unpredictable dynamic predicate behaviour

I have a problem that requires me to add elements to a list that are spread across various predicates. Rather than doing via argument based lists I've opted to use a dynamic list predicate. I simple example can be seen below. When I initially used…
user2211776
  • 239
  • 1
  • 2
  • 11
0
votes
3 answers

Prolog deciding a certain rule to choose depending on input

I've got this prolog problem I can't get around. What I'm trying to achieve is to assert FACT A, retract Fact B when I have input: take and assert Fact B and retract Fact A when I have input put. ie: :- dynamic s/2. :- dynamic s/3. s(P0, s(V, NP))…
macguy
  • 294
  • 3
  • 12
0
votes
2 answers

How can you add elements to a list or compute them from the knowledge base without using findall or assert/retract in Prolog?

I have a knowledge base that consists of students database in a file 'students.pl' like this: % student(Name,Percent,List_of_Marks_in_3_subjects). student('abc',83,[80,80,90]). student('pqr',70,[70,60,80]). student('xyz',76,[80,70,80]). I want to…
shujin
  • 181
  • 12
0
votes
1 answer

Guess the right game for a user with prolog

I am trying to make a program where the user answers questions to find a game, but I couldn't understand how to work with lists and assert. I tried another way with procedure pointsystem. The program is like this: yeah:- write('Please answer the…
Nef
  • 1
  • 1