Module Inheritance

Hello,

I am new to Prolog. I’d like to use a mechanism similar to class inheritance in object-oriented languages, but with SWI Prolog modules. I’d like to have a more specialized module inherit predicates from a more generic module, and then have the ability to override, in the more specific module, the definition of some of the predicates coming from the generic module.

It seems the add_import_module/3 predicate is how you would easily do it in SWI Prolog. But I couldn’t find any examples online.

Would you have knowledge of any examples I could use to see how the add_import_module/3 predicate works?

Thank you in advance,
Quenio

Doing something like that is surely possible. It is also interesting for simple light-weight OO programming. If you want more serious OO programming I suggest to have a look at Logtalk.

There have been several old discussions on how to build simple OO on top of SWI-Prolog’s modules. Roughly it boils down to managing the set of modules some module inherits from and implementing a notion of self by inspecting the call stack and find the original receiver.

2 Likes