Prolog Beginner: Trivial Example that I cannot get to work.

Posted by sixtyfootersdude on Stack Overflow See other posts from Stack Overflow or by sixtyfootersdude
Published on 2010-06-05T18:00:23Z Indexed on 2010/06/05 18:02 UTC
Read the original article Hit count: 149

Filed under:
|
|

I have some prolog. The lessThanTen and example predicates work as expected however the exam predicate does not work.

lessThanTen(9).
lessThanTen(8).
lessThanTen(7).
lessThanTen(6).
lessThanTen(5).
lessThanTen(4).
lessThanTen(3).
lessThanTen(2).
lessThanTen(1).
lessThanTen(0).

example(X) :-
        X is 5.

exam(X) :-
        X is lessThanTen(Y).

Here is the output:

% swipl
...

?- [addv1]. 
Warning: /.../addv1.pl:17:
        Singleton variables: [Y]
% addv1 compiled 0.00 sec, 1,484 bytes
true.

?- lessThanTen(X).
X = 9 ;
X = 8 ;
X = 7 ;
...

?- example(X).
X = 5.

?- exam(X).
ERROR: is/2: Arithmetic: `lessThanTen/1' is not a function
?- exam(5).
ERROR: is/2: Arithmetic: `lessThanTen/1' is not a function

I am thinking that the warning I am getting is pretty key.

© Stack Overflow or respective owner

Related posts about beginner

Related posts about prolog