2 つの文字列または文字列リストを比較するプロローグでプログラムを作成したいと考えています。私は以下を達成したい:
if StringList A == StringList B
{
do this
}
else
do something else
どうすればこれを達成できますか?
2 つの文字列または文字列リストを比較するプロローグでプログラムを作成したいと考えています。私は以下を達成したい:
if StringList A == StringList B
{
do this
}
else
do something else
どうすればこれを達成できますか?
とはどういう意味do this
ですか? doing somewhat
事実と述語しかないので、Prolog で実装するのは困難です。
?- (string1 = string2, X=1); (string1 \= string2, X=2).
X = 2.
1行で行う方法は次のとおりです。
...
(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").