sqr(Number) :-
power(Number,2,A),
write(A).
sqr(In,Out) :-
power(In,2,Out).
power(Base,0,1).
power(Base,Exp,Return) :-
E is Exp - 1,
power(Base,E,R),
Return is R * Base.
Why is power() not coming out of its recursion? Is my exit predicate somehow wrong? It will display the right answer(which suggests that the exit predicate is correct) but will not come back out into the repl when done. A press of the enter key will bring me back to the repl, but I don't think that is how prolog is supposed to work. Any suggestions?
power(Number,2,A),
write(A).
sqr(In,Out) :-
power(In,2,Out).
power(Base,0,1).
power(Base,Exp,Return) :-
E is Exp - 1,
power(Base,E,R),
Return is R * Base.
Why is power() not coming out of its recursion? Is my exit predicate somehow wrong? It will display the right answer(which suggests that the exit predicate is correct) but will not come back out into the repl when done. A press of the enter key will bring me back to the repl, but I don't think that is how prolog is supposed to work. Any suggestions?