views:

93

answers:

1

A simple question, how would I go about declaring a clause which would produce the number specified +1 +2 and +3? I have tried:

addup(Thenumber,Thenumber+1).
addup(Thenumber,Thenumber+2).
addup(Thenumber,Thenumber+3).

but when I run it with say, Thenumber=5, it just returns 5+1 5+2 5+3. I have tried using 'is' to force it to evaluate but it doesn't seem to work. Any help would be appreciated.

+1  A: 

Try this:

addup(X, Y) :- Y is X + 1.

or

addup(X, X+1).

and you question should be addup(2, X)

then X should be 3. If you want to parametrize your addup parameter just make it:

addup(X, Y, X + Y).

and ask with addup(5, 6, X).

anthares
Great, thank you.
Dororo