domains
file = xinput
strlist = string*
mul_strlist = strlist*
predicates
start
reading(mul_strlist)
createlist(string,strlist,strlist,mul_strlist,mul_strlist)
reverselist(strlist,strlist,strlist)
goal
clearwindow,
start.
clauses
start:-
openread(xinput,"data.txt"),
readdevice(xinput),
reading([]).
reading(Mlist):-
not(eof(xinput)),
readln(Line),
createlist(Line,[],New_list,MList,List2),
reading(List2).
reading(Mlist):-
write(Mlist),
closefile(xinput).
createlist(Line,Old_list,New_list,List1,List2):-
Line <> "",
fronttoken(Line,Token,Rest),
New_list = [Token | Old_list],
createlist(Rest,New_list,Blank_list,List1,List2).
createlist(_,Old_list,[],List1,List2):-
reverselist(Old_list,[],New_list),
List2 = [New_list | List1].
reverselist([],Inputlist,Inputlist).
reverselist([Head | Tail],List1,List2):-
reverselist(Tail,[Head | List1],List2).