Two more arities of the naive memoization wrapper:
table-1: predicate (1-arg) tabling. Cache entry is :ok / :no.
Demonstrated with a tabled membero-as-predicate.
table-3: 3-arg (i1 i2 output) tabling. Cache key joins the two
inputs; cache value is the output value list.
Canonical demo: tabled Ackermann.
(ack-o 0 0 q) -> 1
(ack-o 2 3 q) -> 9
(ack-o 3 3 q) -> 61
A(3,3) executes A(2,..) many times, A(1,..) more, A(0,..) most. With
table-3 each (m, n) pair is computed once.
6 new tests, 644/644 cumulative.
`table-2` wraps a 2-arg (input, output) relation. On a ground input
walk, looks up the (string-encoded) cache key; on miss, runs the
relation, drains the answer stream, extracts walk*-output values from
each subst, stores them, and replays. On hit, replays the cached
values directly — no recomputation.
Cache lifetime: a single global mk-tab-cache (mutated via set!).
mk-tab-clear! resets between independent queries.
Canonical demo: tabled fib(25) = 75025 in ~5 seconds; the same naive
fib-o times out at 60s. Memoization collapses the exponential redundant
recomputation in the binary recursion.
Limitations (deferred to future SLG work): cyclic recursive calls with
the same ground key still diverge — naive memoization populates the
cache only AFTER computation completes, so a recursive call inside its
own computation can't see the in-progress entry. The brief's "tabled
patho on cyclic graphs" use case requires producer/consumer
scheduling and is left for a future iteration.
12 new tests, fib(0..20) + ground-term predicate + cache-replay
verification. 638/638 cumulative.