Adding facts to an existing prolog file

I am having trouble embedding facts in an existing Prolog file without overwriting the original content.

Suppose I have a test.pl file:

:- dynamic born/2. 

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

If I upload this to the prolog and I state more facts:

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

I know that I can save this by doing:

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

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

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

This is problematic because if I reload this file, I cannot insert more facts into test.pl because ": - dynamic born / 2." no longer exists.

I read somewhere that I could:

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

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

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

By the way, I use the Sicstus prolog. Does it matter?

Thank!

0
source share
1

, , , , . -

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

, . , , save_program/1/2 restore/1.

append/1 .

+2

Source: https://habr.com/ru/post/1691992/


All Articles