0

我有以下数据库:

vegetarian(jose).
vegetarian(james).
vegetable(carrot).
vegetable(egg_plant).
likes(jose,X):-vegetable(X).
loves(Who,egg_plant):-vegetarian(Who).

当我进行查询时,vegetarian(_).我期望得到_ = jose; _ = james.,但我却得到true; true.

如果我改为这样做vegetarian(X).,那么我会得到预期的答案X = jose; X = james. 为什么会有这种差异?

4

1 回答 1

1

如果您使用的是 SWI-Prolog,您可以使用标志toplevel_print_anon) 来控制它。但是,由单个下划线 ( _) 组成的名称是特殊的并且从不打印。

$ swipl dd.pl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- set_prolog_flag(toplevel_print_anon, true).
true.

?- vegetarian(_X).
_X = jose ;
_X = james.

?- vegetarian(_).
true ;
true.

?- set_prolog_flag(toplevel_print_anon, false).
true.

?- vegetarian(_X).
true ;
true.
于 2021-01-02T19:42:34.557 回答