gpt4 book ai didi

Prolog 二叉树 - 语法错误 : Operator Expected

转载 作者:行者123 更新时间:2023-12-03 08:24:01 25 4
gpt4 key购买 nike

我试图在 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, [], []).

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

最佳答案

Left(_,_, New, T)

不是一个有效的复合术语,因为仿函数可能不是一个变量(大写的标识符)。采用
left(_, _, New, T)

相反,对于 Right 也是如此.

关于Prolog 二叉树 - 语法错误 : Operator Expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10372342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com