2
% expensiveComp(+A,-Result)
% otherRule(+Arg1,Arg2+,-Result)
% r(+A,+B,C)
r(A,B,C) :-
  expensiveComp(A,Result),
  otherRule(Result,B,C).

If r is called multiple times with the same value for A will expensiveComp necessarily be reevaluated each time r is called, or are there circumstances under which Prolog would just bind a cached value to Result?

Are some implementations of Prolog better at knowing when they don't need to reevaluate a rule?

dougcosine
  • 161
  • 1
  • 10
  • 1
    You might have side-effects so you can't assume or prove, in general, that rules can be automatically memoized. – coredump Jul 31 '15 at 08:08
  • 1
    @coredump So no implementations of Prolog try to determine whether a rule can be safely memorized? – dougcosine Jul 31 '15 at 08:18
  • 1
    I just found this, which is relevant for your question http://stackoverflow.com/questions/6970408/predicate-cache – coredump Jul 31 '15 at 08:20
  • I am not aware of any Prolog system that has memoization turned on by default. – repeat Jul 31 '15 at 09:24

1 Answers1

2

There's a number of Prolog implementations which feature support for different kinds of memoization, commonly called "tabling" in Prolog-lingo: , , .

repeat
  • 18,496
  • 4
  • 54
  • 166