I want to write a program in prolog that compares two strings or string lists. I want achieve the following:
if StringList A == StringList B
{
do this
}
else
do something else
How can I achieve this?
I want to write a program in prolog that compares two strings or string lists. I want achieve the following:
if StringList A == StringList B
{
do this
}
else
do something else
How can I achieve this?
What do you mean by do this
? It hard to implement doing somewhat
in Prolog, because all that you've got is facts and predicates.
?- (string1 = string2, X=1); (string1 \= string2, X=2).
X = 2.
Here's how you'd do it in a single line:
...
(A = B -> do this ; do something else)
...
/*SWI prolog code*/
string1(progga).
string2(ikra).
go:-
write("Enter your name"),
nl,
read(X),nl,
string1(Y),
X=@=Y,nl, write("Matched");
write("not Matched"),go2.
/*Another way to*/
go2:-
string1(A),
string2(B),
A=@=B,nl, write("Matched");
write("not Matched").