I am trying to write a program to determine if a sentence is a palindrome. This is what I have so far:
palindrome :- write('Sentence: '),
read(Word),
name(Word,List),
palCheck(List).
palCheck(List) :- reverse(List,List).
reverse(L1,L2) :- rev(L1,[],L2).
rev([],L,L).
rev([H|L],L2,L3) :- rev(L,[H|L2],L3).
The problem I have is when I get to a space or an uppercase letter. What I ultimately want is to be able to write DoD dod and get it to pass. I have tried using downcase_atom(X,Y), but having trouble using it as the sentence is something other than an atom.
read/1 acts in a peculiar way: it’s a very powerful primitive, able to fully parse Prolog syntax. But the space make the input ill formed. Then surround the literal with quotes, or use some other input primitive: see your Prolog manual!
In SWI-Prolog, this query does the check: