2

代码如下:

DOMAINS
name = valentin; leonid; valery; andrew; michael
faculty = physics; history; biology; geography
instrument = sax; piano; bass; drums
student = student(name, instrument, faculty)

PREDICATES
nondeterm student(name, instrument, faculty)

CLAUSES
student(michael, sax, _).
student(_, piano, physics).
student(_, drums, _) :- student(leonid, _, _); student(michael, _, _); student(valentin, _, _); student(andrew, _, _).
student(_, _, geography) :- student(michael, _, _); student(valentin, _, _); student(valery, _, _); student(andrew, _, _).
student(michael, _, _) :- student(_, _, physics); student(_, _, geography); student(_, _, biology).
student(andrew, _, _) :- student(_, _, physics); student(_, _, history); student(_, _, geography).
student(andrew, _, _) :- student(_, sax, _); student(_, bass, _); student(_, drums, _).
student(valery, _, _) :- student(_, _, geography); student(_, _, biology); student(_, _, history).
student(_, drums, _) :- student(_, _, physics); student(_, _, geography); student(_, _, biology).
student(leonid, _, _) :- student(_, sax, _); student(_, piano, _); student(_, drums, _).

GOAL
student(valentin, Instrument, Faculty).

我使用 Visual Prolog 5。这段代码可以编译,但编译器说有未绑定的变量:_ 行中的变量:

student(michael, sax, _).
student(_, piano, physics).

以及在地理原子之前的第二个 _ 变量:

student(_, _, geography) :- student(michael, _, _); student(valentin, _, _); student(valery, _, _); student(andrew, _, _).

是否有可能使此代码工作?

4

0 回答 0