database
unsorted_db(string,integer)
sorted_db(string)
predicates
reading
writing
removing
serching(integer)
go(integer)
goal
clearwindow,
reading,!,
serching(1),
write("String in sorted order"),nl,
writing,
removing.
clauses
reading:-
NumRead = 10,
go(NumRead).
go(0).
go(Num):-
write("Enter any string = "),
readln(Name),
str_len(Name,Len),
asserta(unsorted_db(Name,Len)),
N = Num - 1,
go(N).
writing:-
sorted_db(Name),
write(Name),nl,
fail.
writing.
serching(Max):-
unsorted_db(Name,Max),
assertz(sorted_db(Name)),
retract(unsorted_db(Name,Max)),
serching(Max).
serching(Max):-
Max = 32767.
serching(Max):-
Max1 = Max + 1,
serching(Max1).
removing:-
retract(sorted_db(_)),
fail.
removing.