prolog-assert

GNU Prolog assert error

ⅰ亾dé卋堺 提交于 2019-12-28 06:59:06
问题 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: error(existence_error(procedure,assert/1),top_level/0) {2} What am I exactly missing? Appreciated. 回答1: Use assertz/1 or asserta/1 instead. GNU-Prolog does not provide assert/1 because only asserta/1 and assertz/1 are defined in the standard. Note that while asserta/1 always had one

Calling facts from database in prolog

眉间皱痕 提交于 2019-12-11 04:53:57
问题 I've inserted the given context free grammar into the database using assert(....) If the grammar is something like S-->a,S,b S-->c This grammar is inserted into the database. I have to write a dcg to generate sentences for the cfg in the database. For example if i define the dcg in this way myDcg('S',str) , the 'S' (non terminal) should be called or substituted by aSb or c|d or so. The problem is how can i call/substitute 'S' by facts from the database each time a non terminal('S') is

Appending facts into an existing prolog file

自作多情 提交于 2019-12-10 12:10:54
问题 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 facts: | ?- assert(born(laura,kent)). yes I'm aware I can save this by doing: |?- tell('test.pl'),listing(born/2),told. Which works but test.pl now only contains the facts, not the ":- dynamic born/2": born(john,london). born(tim,manchester). born(laura

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

限于喜欢 提交于 2019-12-01 04:42:01
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 the value using retractall and assert because in Prolog we cannot assign values to variable twice using is (thus making almost every variable that needs modification, global). I have come to know that this is not a good practice in Prolog. In this regard I would like to ask: Why is it a bad practice in Prolog (though i myself don't like to go through

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

北慕城南 提交于 2019-12-01 02:17:57
问题 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 the value using retractall and assert because in Prolog we cannot assign values to variable twice using is (thus making almost every variable that needs modification, global). I have come to know that this is not a good practice in Prolog. In this

Prolog - ASSERT and RETRACT

让人想犯罪 __ 提交于 2019-11-27 20:29:33
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 then the database changes are lost. So I was wondering, is there any way of making it so that the assert and retract predicates can make permanent changes to the Prolog .pl file? Thanks I can suggest you a very simple way of doing this. 1 ?- assert(a(1)). true. 2 ?- assert(a(2)). true. 3 ?- assert(a(3)). true. 4 ?- a(A). A = 1 ; A = 2 ; A = 3. 5 ?-

Prolog - ASSERT and RETRACT

时间秒杀一切 提交于 2019-11-26 20:23:22
问题 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 then the database changes are lost. So I was wondering, is there any way of making it so that the assert and retract predicates can make permanent changes to the Prolog .pl file? Thanks 回答1: I can suggest you a very simple way of doing this. 1 ?-