此代码有什么问题
frequency(f1).
frequency(f2).
frequency(f3).
allocation(z1,z2,z3,z4,z5,z6,z7,z8) :-
frequency(z1), frequency(z2), frequency(z3), frequency(z4), frequency(z5), frequency(z6), frequency(z7), frequency(z8),
z1\==z2, z1\==z3, z2\==z4, z2\==z3, z3\==z4, z3\==z6, z4\==z5, z4\==z6, z4\==z7, z6\==z7, z6\==z8.
?- allocation(f1,f2,f3,f1,f2,f3,f2,f3).
语法错误:。或表达式后期望的运算符
答案 0 :(得分:2)
以下突出显示的代码应阐明目标allocation(f1,f2,f3,f1,f2,f3,f2,f3)
无法成功的原因:
allocation(Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8) :- dif(Z1,Z2), dif(Z1,Z3), dif(Z2,Z3), dif(Z2,Z4), dif(Z3,Z4), dif(Z3,Z6), dif(Z4,Z5), dif(Z4,Z6), dif(Z4,Z7), dif(Z6,Z7), dif(Z6,Z8), maplist(frequency, [Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8]).
请注意在上面的代码中使用dif/2
代替(\==)/2
吗?
prolog-dif保留 logical-purity ,更加容易debugging !