Im trying to write a binary tree in prolog but getting the following error:
Syntax error: Operator expected
The error occurs here in the first call to 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).
I’m using the following node:
node(node, node, [], []).
Any and all help is appreciated.
is not a valid compound term, since the functor may not be a variable (uppercased identifier). Use
instead, and similarly for
Right.