根據下面的內容,當試圖斷言事實時,我有可預期的類型錯誤可調用,我認爲逐行插入事實成功發生。但是,asserta不能很好地工作。儘管如此,我想轉換爲使用字符串(string_codes(?字符串?代碼))或插入的代碼行,但它不會成功從外部文件中讀取全部事實
start:-
writeToFile,
readFromFile,
usereduc(C,D),
writef(C),
writef(D).
writeToFile:-
writef('What is your Name'),nl,
read(Name),
writef('What is your country'),nl,
read(Country),
writef('What is your education'),nl,
read(Education),
open('output.txt',write,Out),
write(Out,usercountry(Name,Country)),nl(Out),
write(Out,usereduc(Name,Education)),
close(Out).
readFromFile:-
open('output.txt',read,In),
repeat,
read_line_to_codes(In,X),nl,
readfactsFromfile(X),asserta(X),
close(In).
readfactsFromfile(end_of_file).
readfactsFromfile(X):-
writef(X),
string_codes(S, X),
asserta(S),!,
fail.
非常感謝你,我也用persistency.pl,它看起來很好 –