We want now to evaluate if any word in our language which is only made with the letters {a,b}, is a palindrome or not. I did code the program below, but I want it to accept only letters a or letters b and none other, if we input any other letters then it’s false. Example : [a,b,a] is correct, [b,a,b] is correct but [b,b,a] or [a,b,a,b] is incorrect.
Here is what I tried to do, but I just want prolog to return true if the word is a palindrome with only the letters a or b and not any other letters. I hope someone will help me.
reverse(X,Y) :- reverse(X,[],Y).
reverse([],X,X).
reverse([X|Y],Z,T) :- reverse(Y,[X|Z],T).
langage6([]).
langage6(L):-
reverse(L, L).