Replace third(Tail,Result)
with third(Tail,[Result])
:
test([Head|Tail], Subject, Z):-
second(Tail, Subject2),
Subject2==Subject,
third(Tail,[Result]),
Result =< 4.0,
Z=[Head|Tail].
Вопрос
I want to write a SWI-Prolog program, which tests if the result is lower than 4.0.
Therefore I pass a list like this [Name, Subject, Result]
, the subject and the name for the return value.
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].
Now if I execute with the following parameters:
test([smith, mu, 2.4], mu, R).
There is an error occuring:
ERROR: =</2: Type error: `character' expected, found `2.4'
I just can't find a way to fix it.
Решение
Replace third(Tail,Result)
with third(Tail,[Result])
:
test([Head|Tail], Subject, Z):-
second(Tail, Subject2),
Subject2==Subject,
third(Tail,[Result]),
Result =< 4.0,
Z=[Head|Tail].