I have the following prolog expression in my file which is pretty self explanatory. I have all the required functions which is needed for this rule (call it 1) implemented and tested correctly.
cal(plus(X,Y),Z):-cal(X,int(Z1)),cal(Y,int(Z2)),add(Z1,Z2,Z3),Z=int(Z3) ; cal(X,real(Z1)),cal(Y,real(Z2)),add(Z1,Z2,Z3),Z=real(Z3).
After hours of trying I couldn't figure out the following:
?-call(plus(int(9),int(10)),Z).
works correctly and returns:-
Z = int(19).
but it doesn't unify with
?-call(plus(real(9.0),real(10.0),Z).
I tried many things and concluded that this is due to the integer part(before ;) in the rule 1 been specified first than the real part(I exchanged the two and it started working in the reverse way). It tries to unify with the first part and goes on repeatedly. As there is no such fact out there it just goes into an infinite loop. Please specify an alternative way to do the same. This is the only part of my assignment that is left and I am struck on it for hours.
Thanks in advance!
Well, here's the answer.
You should call cal function only once for a particular input . Redundant calling causes problems.