Logo 
Search:

Artificial Intelligence Article

Submit Article
Comments on Prolog problem to add two numbers

Prolog problem to add two numbers.

?- start.
X= |: 1.
Y= |: 2.
Sum is 3
yes


Nitin Tripathi
Nitin Tripathi from United StatesMay 23
Hello Milind,
I am trying to learn PROLOG, and saw this code.

But in my case,
I can see the following output.
can you please elaborate the behavior.

[trace] [4] 257 ?- start.
Call: (30) start ? creep
Call: (31) sum ? creep
Exit: (31) sum ? creep
Call: (31) nl ? creep

Exit: (31) nl ? creep
Exit: (30) start ? creep
true .


While my code is as follow.

%predicates
start.
sum.
%clauses

start :- sum, nl.

sum :-
write("X = "),
readreal(X),
write("Y = "),
readreal(Y),
S = X + Y,
write("SUM is = "),
write(S).


Please enter your Comment
  • Comment should be atleast 15 Characters.
  • Please put code inside [Code] your code [/Code].