「7週間で7つの言語」atmを読んでいて、「no」の応答がわからないPrologクエリに困惑しています。
ファイルは次のfriends.pl
ようになります。
likes(wallace, cheese).
likes(grommit, cheese).
likes(wendolene, sheep).
friend(X, Y) :- \+(X = Y), likes(X, Z), likes(Y, Z).
次のような簡単なクエリを実行できます。
| ?- ['friends'].
compiling /home/marc/btlang-code/code/prolog/friends.pl for byte code...
/home/marc/btlang-code/code/prolog/friends.pl compiled, 12 lines read - 994 bytes written, 8 ms
yes
| ?- friend(wallace,grommit).
yes
| ?- friend(wallace,wendolene).
no
これはすべて予想通りです。ここで、クエリに変数を導入します。私の意図は、PrologがWallaceのすべての友達のリストを私に与えるということです。私は期待していX = grommit
ますが、私は得ていno
ます:
| ?- trace.
The debugger will first creep -- showing everything (trace)
yes
{trace}
| ?- friend(wallace,X).
1 1 Call: friend(wallace,_16) ?
2 2 Call: \+wallace=_16 ?
3 3 Call: wallace=_16 ?
3 3 Exit: wallace=wallace ?
2 2 Fail: \+wallace=_16 ?
1 1 Fail: friend(wallace,_16) ?
no
{trace}
X
(_16
)を。と統合しようとさえしませんgrommit
。なんで?