Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with appending facts into an existing prolog file.

Status
Not open for further replies.

vuj

Programmer
May 28, 2010
2
GB
Hi,

I'm having trouble inserting facts into an existing prolog file, without overwriting the original contents.

Suppose I have a file test.pl:

Code:
:- dynamic born/2. 

born(john,london).
born(tim,manchester).

If I load this in prolog, and I assert more facts:

Code:
| ?- assert(born(laura,kent)).
yes

I'm aware I can save this by doing:

Code:
|?- tell('test.pl'),listing(born/2),told.

Which works but test.pl now only contains the facts, not the ":- dynamic born/2":

Code:
born(john,london).
born(tim,manchester).
born(laura,kent).

This is problematic because if I reload this file, I won't be able to insert anymore facts into test.pl because ":- dynamic born/2." doesn't exist anymore.

I read somewhere that, I could do:

Code:
append('test.pl'),listing(born/2),told.

which should just append to the end of the file, however, I get the following error:

Code:
! Existence error in user:append/1
! procedure user:append/1 does not exist
! goal:  user:append('test.pl')

I need to be able to retain the old facts in the file and append new ones.

Btw, I'm using Sicstus prolog. Does this make a difference?

Any help would be much appreciated, thanks!
 
Use this:

?- tell('test.pl'), listing, told.

'listing' will list everything in the KB, not only 'born' clauses
 
Don't you use the facts born/2 in a program ?
You can write :-dynamic born/2. in the file where you load the facts born/2.
 
Thanks for your replies.

I've managed to get it working by writing ":- dynamic born/2" in the file before listing the facts, as suggested above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top