user3066261
user3066261

Reputation: 101

Basic error in Prolog

I have this: problem(a(1,2,3),P) And I need to get this: P = [e(1, 3), e(2, 0)]

I just started with Prolog a few days ago and I wrote this:

problem([a(X,Y,Z)],P) :- P is [e(X,Z),e(Y,0)].

But I only get a false by answer. What error did I make?

Upvotes: 1

Views: 34

Answers (1)

Paulo Moura
Paulo Moura

Reputation: 18663

The standard is/2 predicate is used for evaluating arithmetic expressions. In your case, a simple fact would suffice:

problem(a(X,Y,Z), [e(X,Z),e(Y,0)]).

For example:

?- [user].
problem(a(X,Y,Z), [e(X,Z),e(Y,0)]).
|: ^D

?- problem(a(1,2,3), P).
P = [e(1, 3), e(2, 0)].

Upvotes: 2

Related Questions