我写了一个简单的程序,可以在序言中找到两个数字中的最大值
domains
x,y,z=integer
predicates
bigger(x,y,z)
clauses
bigger(X,Y,Z):-
X>Y,Z=X.
bigger(X,Y,Z):-
X<Y,Z=Y.
goal
bigger(5,7,X).
但是每当我运行程序时,都会出现错误:
compiling /home/prabin/large_number.pl for byte code...
/home/prabin/large_number.pl:2:5: syntax error: . or operator expected after expression
/home/prabin/large_number.pl:11:5: syntax error: . or operator expected after expression
2 error(s)
compilation failed
为什么会这样?
答案 0 :(得分:0)
您的源代码用于Visual Prolog(或更旧的TurboProlog)。删除:
domains
x,y,z=integer
predicates
bigger(x,y,z)
clauses
和
goal
bigger(5,7,X).
只留下
bigger(X,Y,Z):-
X>Y,Z=X.
bigger(X,Y,Z):-
X<Y,Z=Y.
保存固定代码后,您可以在顶级解释器中输入目标:
| ?- bigger(5,7,X).
X = 7
yes