0

2 つの文字列または文字列リストを比較するプロローグでプログラムを作成したいと考えています。私は以下を達成したい:

if StringList A == StringList B
   {
     do this
   }
else
   do something else

どうすればこれを達成できますか?

4

3 に答える 3

2

とはどういう意味do thisですか? doing somewhat事実と述語しかないので、Prolog で実装するのは困難です。

?- (string1 = string2, X=1); (string1 \= string2, X=2).
X = 2.
于 2012-10-30T20:50:39.220 に答える
1

1行で行う方法は次のとおりです。

...
(A = B -> do this ; do something else)
...
于 2012-10-30T20:47:48.457 に答える
0
 /*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").
于 2019-08-04T09:16:29.493 に答える