我目前正在为一个班级学习 Prolog。我正在使用 GNU Prolog 来定义一个规则class_info(X,Y)和一个类似的规则,其中X是教授的名字,Y将是信息的输出。例如:
?- class_info(steve, Y).
Y = math ;
false.
Run Code Online (Sandbox Code Playgroud)
但是我只知道如何返回规则中的代数表达式,而不知道上面的那个。
假设我有以下事实。
/*facts */
job(steve, professor).
job(john, professor).
teaches(steve, math).
teaches(john, chemistry).
class(math, calculus).
class(chemistry, organic).
class(math, algebra).
class(chemistry, basic).
%rule
class_info(X, Y) :-
%absolutely have no idea what do here, 'is' does not work, since it's only for algebraic expressions
.
exact_class(X, Y) :-
%exact_class(steve, Y). returns Y = calculus? and Y = algebra upon pressing ';'
.
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。我不是在寻找代码,而是在寻找指向正确方向的东西。Prolog GNU …
prolog ×1