Storing and Querying Object Tuples with Prolog


I’m working on a project with a knowledgebase interface:

    public interface IKnowledgebase
        object Query(string functor, params object[] tuple);
        void Store(string functor, object value, params object[] tuple);
        /* ... */

For each functor string, I want to store tuples of .NET objects and, per each tuple, a value: (tuple[0], tuple[1], ..., tuple[n], value). I want to then query the storage to obtain the stored or derived value for a given tuple.

In Prolog, this resembles asserting: functor(tuple[0], tuple[1], ..., tuple[n], value) and querying for the stored value with functor(tuple[0], tuple[1], ..., tuple[n], X).

The knowledgebase interface will also support adding and removing logical rules. SWI Prolog is a natural fit for the project. I am exploring implementing the knowledgebase interface using SWI Prolog using a .NET implementation that I worked on.

Instead of atoms, each tuple element and value is either a builtin type (e.g. int, float) or a .NET object.

Question 1

Has anyone seen this scenario before? Does anyone know of fast ways of using the SWI Prolog C/C++ API to accomplish this? Should I make use of indices from a list of stored object references, use the objects’ pointers, or …?

Question 2

Is there a name for the technique of including a Boolean value in compound expressions to indicate their truth values, as per: functor(x, y, true) or functor(x, y, false)? Are there publications on the approach? Should I attribute some person or people when describing the technique?

It might be that you mean “reification”. One place where you find this terminology in the SWI-Prolog docs is in this subsection of the manual.

There is also this page by Ulrich Neumerkel:

where you can find, among other things, a library called reif. As far as I am aware there are quite a few answers on the Prolog tag at stackoverlow that use that library, if you want to see example code.

Did I understand your question?

@Boris Yes, “reification” appears to be the terminology. Thank you.