I am considering again varargs in Prolog. Like for the
second or third time. But this time for OO-systems. So
its not really call/n, but (::)/2. But there is a twist,
you can have (::)/2 and call/n combined, so the solution
is then to define (::)/3, (::)/4, ... so that for example
this call here:
?- call(X::invert, Y). /* step 1 */
Gives the same result as:
?- ::(X,invert,Y). /* step 2 */
Which then transforms itself to:
?- X::invert(Y). /* step 3 */
Actually I am skipping step 2 and go directly from step
1 to step 3. But I have some meta_predicate definitions
for step 2, so that pretty printing works.
So what is the benefit of best kept secret in Prolog,
reexport/1 as IS-A and adding an (::)/2 operator:
- Pythonesk methods can be catalogued like any
other predicates. The have the arity N+1, where
N is the number of message parameters. The additional
parameter is self.
- They can be catalogued to the module where they
are defined. Also the module gives already enough
information concerning inheritance, just check
the reexport/1 directives of the module.
- Native tools like apropos/1, edit/1, etc.. work
all unchanged. They can find a Pythonesk method
definition, and they can yield information for this
Pythonesk method or give navigation to this Pythonesk
method. Also a debugger works unchanged.
- Likewise external tools. If your Prolog system uses
some external IDE, cooperates with such an external
IDE, by some wire protocol etc.., not much changes
for this IDE. Pythonesk methods are just predicates
like any other predicate. You should be able to set
break points and even inspect variables. You will see
a self variable, the name is given by the user.
But if call/n is involved, I guess it is recommended to
do some additional meta-predicate definitions, so that these
tools can better understand source code. For example
pretty printing works better with more meta-predicate
definitions. So I am considering varargs again.
Here is what can be done without varargs, just make
some meta-predicate declarations up to some maximum arity:
The meta-predicate definitions for (::)/[4,5,6,..] are here:
http://www.jekejeke.ch/idatab/doclet/blog/en/docs/05_run/05_frequent/standard/apply.html
The meta-predicate definitions for (::)/[2,3] are here:
http://www.jekejeke.ch/idatab/doclet/blog/en/docs/05_run/02_reference/runtime/quali.html
I remember in the past, that introducing varargs alone
doesn't solve the problem. We would also have arity based
meta argument specifiers. So these meta predicate definitions
for example here:
:- meta_predicate ::(?,::(0)).
:- meta_predicate ::(?,::(1),?).
:- meta_predicate ::(?,::(2),?,?).
:- meta_predicate ::(?,::(3),?,?,?).
:- meta_predicate ::(?,::(4),?,?,?,?).
Etc...
How can they be replaced by a single varargs meta-predicate
declaration? We would need to replace the numbers 2, 3, 4, ...
etc.. by a formula arity-2 or somesuch. And let the interpreter
understand such formulas at runtime.