domains
file = xinput
strlist = string*
predicates
start
reading(strlist)
createlist(string,strlist,strlist,strlist)
reverse(strlist,strlist,strlist)
goal
clearwindow,
start.
clauses
start:-
openread(xinput,"data.txt"),
readdevice(xinput),
reading([]).
reading(List):-
not(eof(xinput)),
readln(Line),
createlist(Line,List,Newlist,Act_list),
reading(Act_list).
reading(List):-
reverse(List,[],Reverselist),
write(Reverselist).
createlist(Line,Oldlist,Newlist,Act_list):-
Line <> "",
fronttoken(Line,Token,Rest),
Newlist = [Token | Oldlist],
createlist(Rest,Newlist,List2,Act_list).
createlist(Line,Oldlist,Newlist,Act_list):-
Act_list = Oldlist.
reverse([],Inputlist,Inputlist).
reverse([Head | Tail],List1,List2):-
reverse(Tail,[Head | List1],List2).