OO-Prologs have a long tradition. Chris Moss once handed
me a copy of his book Prolog++. I still have it, I got
it in August 1994, when there was even no Logtalk yet.
Chris Moss, Prolog++: The Power of Object-Oriented and Logic Programming
https://en.wikipedia.org/wiki/Prolog%2B%2B
Of course the goal of any OO system is to make virtual
calls effortless. Otherwise you shouldn't even touch making
an OO system. This has to do that without an effortless virtual
call, many OO typical programming patterns cannot be used.
For example visitor pattern etc.. Such patterns are often
solved Prolog-ish in different ways. But if you solve it
in another way, and if you don't use virtual calls, why
use Logtalk at all. Doesn't make any sense at all. You
can use modules and reexport or use_module to
share code. You also have in the ISO core standard
the following feature:
... have to look it up, either in core or module,
a predicate can be in a state that it is half defined,
i.e. it exists but has no clauses, and throws an
error if invoked ...
Looking at the many modifiers that Java has I
noticed that Logtalk already implements public/1,
private/1 and protected/1.
I do not yet have protected/1. But I got the idea to
implement abstract/1 just now. One could do what some of
the Logtalk prototypes or who knows what do. One could
for example make a pure abstract module as follows:
:- module(arith, []).
:- abstract add/3.
:- abstract sub/3.
:- abstract neg/2.
...
The effect would be that such a half backed predicate
is created, I have already an internal predicate for that,
that can create such predicates:
sys_neutral_predicate(I):
If no predicate has yet been defined for the predicate indicator I, defines a corresponding neutral predicate.
http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/10_docu/02_reference/07_theories/01_kernel/03_body.html
What I do not yet have is an "abstract" attribute of a predicate.
But taking into account this "abstract" attribute, I could adapt
the current style check for modules,
that looks for unimplemented predicates. And maybe I could
also adapt the predicate lookup. This would satisfy some
of the Logtalk software engineering appeal.
In the end I would have both performance and
software engineering appeal.
Even this "abstract" attribute would come very handy for
my Java class auto loader. I could also assign the attribute
to auto loaded classes and members, if they have it already.
Maybe I should do the "abstract" attribute first, and the
"protected" modifier attribute later. Ha Ha. Can be used for
a lot more, already found in the Logtalk univers by
other names. But for example in Java interface classes,
are just classes where all the members are by default
"abstract" and "public". So such things could be also done.
I have actually some use cases for this scenario:
- It serves as a documentation tool, other than
no predicate declared, its abstractly declared.
- It helps in making the code robust, other error
than simply predicate undefined
- It helps in debugging the code, other error than
simply predicate undefined.
Although its not really a contribution to speed. Its a
contribution to make the OO system more complete, and map
some OO patterns, OO practice to the OO system.
The next step would be to allow a modifier for the
module declaration, for example, as such:
:- abstract module(arith, []).
Then term objects and/or proxy objects from the module
arith would not anymore be allowed. Etc.. Etc..
But please note: This would again be based on the native
module system. So that the end-user doesn't have to learn
anything new, execpt the modifiers.