Prolog 语法和谓词逻辑
Prolog syntax and predicate logic
我在点 (THIS-RTE) 和 (Other-RTE) 有 2 个异常我无法修复它可以any1 给我一个关于我做错了什么的提示,因为我很确定我把事情搞砸了。谢谢
decomp([],[],0,0).
decomp([E|T],R,P,I):-
0 is mod(E,2),
decomp(T,R1,P1,I),
R is [E|R1], %**(*THIS-RTE*)** ERROR: is/2: Type error: `[]' expected, found `[2|_G7167]' ("x" must hold one character)
P is 1 + P1.
decomp([E|T],R,P,I):-
not(0 is mod(E,2)),
decomp(T,R1,P,I1),
R is append(E,R1,R), %**(*Other-RTE*)** ERROR: d:/../../../../lab1a.pro:47: evaluable `append(_G5550,_G5551,_G5552)' does not exist, but my clause is right ther
I is 1 + I1.
append(E,[],[E]).
append(E,[A|St],[A|Et]):-
append(E,St,Et).
你的语法有点不对:
R is append(E,R1,R)
应该只是 append(E,R1,R)
因为你传递的是 R
R is [E|R1]
应该直接进入规则 的 header
结果应如下所示:
decomp([],[],0,0).
decomp([E|T], [E|R1], P, I):-
0 is E mod 2,
decomp(T,R1,P1,I),
P is 1 + P1.
decomp([E|T],R,P,I):-
1 is E mod 2,
decomp(T,R1,P,I1),
append(E,R1,R),
I is 1 + I1.
我在点 (THIS-RTE) 和 (Other-RTE) 有 2 个异常我无法修复它可以any1 给我一个关于我做错了什么的提示,因为我很确定我把事情搞砸了。谢谢
decomp([],[],0,0).
decomp([E|T],R,P,I):-
0 is mod(E,2),
decomp(T,R1,P1,I),
R is [E|R1], %**(*THIS-RTE*)** ERROR: is/2: Type error: `[]' expected, found `[2|_G7167]' ("x" must hold one character)
P is 1 + P1.
decomp([E|T],R,P,I):-
not(0 is mod(E,2)),
decomp(T,R1,P,I1),
R is append(E,R1,R), %**(*Other-RTE*)** ERROR: d:/../../../../lab1a.pro:47: evaluable `append(_G5550,_G5551,_G5552)' does not exist, but my clause is right ther
I is 1 + I1.
append(E,[],[E]).
append(E,[A|St],[A|Et]):-
append(E,St,Et).
你的语法有点不对:
R is append(E,R1,R)
应该只是append(E,R1,R)
因为你传递的是R
R is [E|R1]
应该直接进入规则 的 header
结果应如下所示:
decomp([],[],0,0).
decomp([E|T], [E|R1], P, I):-
0 is E mod 2,
decomp(T,R1,P1,I),
P is 1 + P1.
decomp([E|T],R,P,I):-
1 is E mod 2,
decomp(T,R1,P,I1),
append(E,R1,R),
I is 1 + I1.