domains
strlist = string*
predicates
start
createlist(integer,strlist,strlist,strlist)
strcmp(string,string)
charcmp(char,string)
reverse(strlist,strlist,strlist)
goal
clearwindow,
start.
clauses
start:-
createlist(3,[],Newlist,List1),
reverse(List1,[],List2),
List2 = [Str1 | Tail],
Tail = [Str2 | Tail1],
Tail1=[Str3 | Str4],
write("cmp string1 and string2"),nl,
strcmp(Str1,Str2),
write("cmp string1 and string3"),nl,
strcmp(Str1,Str3),
write("cmp string2 and string3"),nl,
strcmp(Str2,Str3).
createlist(Num,Oldlist,Newlist,List1):-
Num > 0,
write("Enter any string ="),
readln(Str),
Newlist = [Str | Oldlist],
NN = Num - 1,
createlist(NN,Newlist,List2,List1).
createlist(_,Oldlist,_,List1):-
List1 = Oldlist.
strcmp(Str1,Str2):-
frontchar(Str1,Ch1,Rest1),
charcmp(Ch1,Str2),
Rest1<>"",
strcmp(Rest1,Str2).
strcmp(Str1,Str2).
charcmp(Ch1,Str2):-
frontchar(Str2,Ch2,Rest2),
Ch1<>Ch2,
Rest2<>"",
charcmp(Ch1,Rest2).
charcmp(Ch1,Str2):-
frontchar(Str2,Ch2,Rest2),
Ch1=Ch2,
write("char=",Ch2),nl.
charcmp(Ch1,Str2).
reverse([],Inputlist,Inputlist).
reverse([Head |Tail],List1,List2):-
reverse(Tail,[Head | List1],List2).