我正在尝试将两个三角形比较两点和高度。
compare_tri( triangle ( point(X1,Y1), point(X2,Y2), H1),
triangle( point(X3,Y3), point(X4,Y4), H2)) :-
A1 is ((X2-X1)*(X2-X1)),
B1 is ((Y2-Y1)*(Y2-Y1)),
C1 is (A1+B1),
D1 is (sqrt(C1)),
S1 is (D1*H1),
A2 is ((X4-X3)*(X4-X3)),
B2 is ((Y4-Y3)*(Y4-Y3)),
C2 is (A2+B2),
D2 is (sqrt(C2)),
S2 is (D2*H2),
( (S1 < S2)
-> (S1 is 2), (S2 is 1)
; (S2 is 2), (S1 is 1)
),
write(S1), write('bigger than '), write(S2).
但是我收到错误消息'syntax operator:operator expected'
有什么问题?
答案 0 :(得分:1)
triangle
和下一个大括号之间必须没有空格:将triangle ( point(X1,Y1)
更改为triangle( point(X1,Y1)
,错误就会消失。
答案 1 :(得分:0)
除了谢尔盖已经解决的语法错误之外,一般的建议是:尝试首先编写可重用的代码。它更容易调试,阅读,记忆......
triangle_area(triangle(point(X1,Y1), point(X2,Y2), H), S1) :-
A1 is ((X2-X1)*(X2-X1)),
B1 is ((Y2-Y1)*(Y2-Y1)),
C1 is (A1+B1),
D1 is (sqrt(C1)),
S1 is (D1*H1).
compare_tri(T1,T2) :-
triangle_area(T1,S1),
triangle_area(T2,S2), etc etc...