Can match in-frame-constructed terms to the rule database?

Suppose I have facts that can be /1 and /2 versions, I can relate one with the other with a rule:

t(T,[T]) :- t(T).

and hope that t(1,[1]) can be found whenever t(1) is asserted.

t(1).
?- t(1,X).   % true, X = [1]

However, this relied upon t(1) being found in the database.

Is this possible to use rules only for matching on the contents of the fact the database? Suppose I have terms that are constructed during the frame only, can the rulebase be used (for example, to allow t(X,[X]) to be used whenever t(X) is found)?

?- t(1,[X])=t(1).

In practice, Iā€™m trying to get the following to succeed:

?- maplist([t(_,R),R]>>(true), 
        [t(1,[1]), t(2)],           % Input list must be normalized for the maplist predicate
        Result).
false.

ā€¦ fails because t(2) is not in the database when t(_,R) is unified with the rule body of t(T,[T]).

I guess another way of asking this is: if we want to test if Term1 can be unified with Term2, assuming some fact F, is assert the only mechanism for assuming a fact?

Not sure if this is helpful, but instead of using assert i once used assoc [1] to assert linked facts as a dynamic structure that is passed as assoc arguments across a program.

So, facts can also live in a dynamic structure that can be queried.

To keep the dynamic structure across predicate calls intact would need some mechanism for persistence ā€“ assert or otherwise.

[1] https://www.swi-prolog.org/pldoc/man?section=assoc-modifications

1 Like