Search code examples
prologpalindrome

Prolog not printing statements


I was trying this palindrome program in prolog, the logic works but write operation is not working. So what is the problem in the code?

palin(List1):- findrev(List1,[],List2), compare(List1,List2).

findrev([],List1,List1).

findrev([X|Tail],List1,List2):-
    findrev(Tail,[X|List1],List2).

compare([],[]):-
    write("\nList is Palindrome").

compare([X|List1],[X|List2]):-
    compare(List1,List2).

compare([X|List1],[Y|List2]):-
    write("\nList is not Palindrome").

Solution

  • It works for me. I use SWI prolog. And try replace " with '. Because with "Something" it prints it as list of numbers, not as string.