1
這是我的序言數據庫代碼。將查詢結果寫入序言中的文件
:-
dynamic myTable/2.
init :-
removeAll,
asserta(myTable('avalue', 'another value')),
asserta(myTable('avalue1', 'another value 1')),
asserta(myTable('avalue2', 'another value 2')),
asserta(myTable('avalue3', 'another value 3')),
asserta(myTable('avalue4', 'another value 4')).
read(Col1, Col2) :-
myTable(Col1, Col2).
saveQueries(FileName) :-
tell(FileName).
stopSavingQueries :-
told.
我想開始將prolog輸出保存到文件中。對動態數據庫進行一些查詢,將其保存到文件中,然後停止保存查詢。它看起來像這樣
?- init.
true.
?- saveQueries('queries.txt').
true.
?- read(Col1, Col2).
...
?- stopSavingQueries.
true.
當我運行此代碼文件queries.txt
創建。當我運行read(Col1, Col2).
時,我在控制檯中看到輸出,並且文件queries.txt
保持爲空。