2012-04-29 61 views
0

我试着写在序言二叉树,但得到以下错误:Prolog的二叉树 - 语法错误:运营商预计

Syntax error: Operator expected 

这里出现的错误在第一次调用addChildren:

addChildren(node(Left, Right, Cand, [(Name, Profit, Weight)|T])):- 
getTotalWeight(Cand, 0, Total), 
%if total weight is less than 20 
((Total + Weight) < 20 -> %then 
    New = [Cand | (Name, Profit, Weight)], 
    addChildren(Left(_,_, New, T)), %error here 
    addChildren(Right(_,_, Cand, T)) 
; %else 
    %end). 

我使用以下节点:

node(node, node, [], []). 

任何和所有帮助表示赞赏。

回答

2
Left(_,_, New, T) 

不是一个有效的复合项,因为函数可能不是一个变量(大写的标识符)。使用

left(_, _, New, T) 

代替,并且类似地对于Right

+0

和函数定义'addChildren(节点(左,右,C和[(名称,利润,重量)| T])): - ',太? – rhalliwell1 2012-04-29 13:16:08

+0

@ rhalliwell1:正如我所解释的,这是一个语法错误。 – 2012-04-29 13:20:02

+0

非常感谢:) – rhalliwell1 2012-04-29 13:22:44