cache/2 (i)
This builtin predicate provides support for tabling in Prova. It enables the literal in its only argument for caching. The current implementation in Prova 3.0 keeps the cached answer set for the literal indefinitely.
The following example runs the Hanoi Tower puzzle for 20 disks, which would have been prohibitively long if the cache predicate was not used. Naive implementations in Haskell or Scala also suffer unless tabling is explicitly added.
Tabling also helps to avoid infinite looping in code as the example below shows.
This returns only one solution X=a.
Labels: