我想写一个SWI-Prolog程序,它测试结果是否低于4.0。
因此,我传递了一个像[Name, Subject, Result]
这样的列表,主题和返回值的名称。
third([Head|Tail], Z) :-
Z = Tail.
second([Head|Tail], Z) :-
Z = Head.
test([Head|Tail], Subject, Z) :-
second(Tail, Subject2),
Subject2==Subject,
third(Tail,Result),
Result=<4.0,
Z=[Head|Tail].
现在,如果我使用以下参数执行:
test([smith, mu, 2.4], mu, R).
发生错误:
ERROR: =</2: Type error: `character' expected, found `2.4'
我找不到解决方法。
答案 0 :(得分:1)
将third(Tail,Result)
替换为third(Tail,[Result])
:
test([Head|Tail], Subject, Z):-
second(Tail, Subject2),
Subject2==Subject,
third(Tail,[Result]),
Result =< 4.0,
Z=[Head|Tail].