0

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?

Tariqulazam
  • 4,535
  • 1
  • 34
  • 42
Jro
  • 466
  • 2
  • 6
  • 14

3 Answers3

2

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.
  • Soory I did not explain properly. I need to write a program in prolog like this; If (stinglistA == 'C', 'a', 'n','c', 'e','l') { M1= 'C' and M2 ='a') else M1 = M1 and M2 = m2 – Jro Oct 31 '12 at 20:02
1

Here's how you'd do it in a single line:

...
(A = B -> do this ; do something else)
...
Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
CapelliC
  • 59,646
  • 5
  • 47
  • 90
-1
 /*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").
Progga Ilma
  • 578
  • 6
  • 8