我想划分给定列表的长度。我知道如何分割,我知道如何获得List的长度,但使用两个谓词对我来说都不起作用。这是我得到的:
halflength(List,Halflength) :- length([List,Length]), Halflength is Length/2.
[trace] ?- halflength([a,b,c],Halflength).
Call: (7) halflength([a, b, c], _G15025) ? creep
Call: (8) length([[a, b, c], _G15108]) ? creep
ERROR: halflength/2: Undefined procedure: length/1
ERROR: However, there are definitions for:
ERROR: length/2
Exception: (8) length([[a, b, c], _G15108]) ? creep
Exception: (7) halflength([a, b, c], _G15025) ? creep
答案 0 :(得分:5)
下面:
Undefined procedure: length/1
您只使用一个参数调用length
,列表:
length([List,Length])
这应该是:
length(List, Length)