Remembering goals in Prolog

Is it possible for prolog to memoize calculated targets?

Under this, I want to say that Prolog should not recompile the goals that were previously calculated.

So, for example, for me the same calculations:

goal([first, one], he, she, var(cat, 5)).
goal([first, one], he, she, var(cat, 5)).

but not

goal([first, one], he, she, var(cat, 6)).

Thus, in fact, it should be possible to combine goals.

+4
source share
1 answer

Many Prolog systems provide the ability to implicitly record such results. This is called a table ; see the Prolog documentation on how to enable it.

Prolog , ( ) , assertz/1 .

:

:- dynamic memo_/1.

memo(Goal) :-
    (    memo_(Goal) -> true
    ;    Goal,
         assertz(memo_(Goal))
    ).

emptor...

, , , .

+2

All Articles