I have a function like this:
myFunction(V1, V2, Result) :-
Result is V1/V1cover + V2/V2cover,
write(Result).
myFunction(0,0,0).
keepValue(V1,V2,V1cover,V2cover) :-
V1cover is V1,
V2cover is V2.
There are other functions that call myFunction many times and get the Result back. However, I would like to get the first Result that myFunction is called first time and keep it to use for calls later(In this case, it is V1cover and V2cover). For example, first time, myFunction(4,4,A) is called. Then it returns A = 2. After that I would like to keep the value of V1cover(4) and V2cover(4) to use for next called times. How I can do that? I tried to apply a cached techonology like and apply it into myFunction:
:- dynamic(cachedGoal_sol/2).
reset :-
retractall(cachedGoal_sol(_, _)).
eq(A, B) :-
subsumes_term(A, B),
subsumes_term(B, A).
cached_call(Goal) :-
\+ (cachedGoal_sol(First,_), eq(First, Goal)),
copy_term(Goal, First),
catch(
( Goal,
assertz(cachedGoal_sol(First, Goal)),
fail
),
Pat,
(reset, throw(Pat))).
cached_call(Goal) :-
cachedGoal_sol(First, Results),
eq(First, Goal),
Results = Goal.
myFunction(V1, V2, Result) :-
**cached_call(keepValue(V1,V2,V1cover,V2cover),**
Result is V1/V1cover + V2/V2cover,
write(Result).
but it doesn't work, when I try to run the second time myFunction(2,3,A) and trace the program, it actually stores solution of the first call but I couldn't get the first values of V1cover, V2cover since eq() in the second cached_call() fails. Is there a way to only get values of V1cover, V2cover without touching to V1,V2 since they are input? Thanks very much for your answer.