Paul Tarau schrieb:
> Jinni Prolog is about 4 secs, Styla is about 18 on my Mac Air.
Ok
> P.S. As functional-style Scala with case classes transliterates almost
> one-to-one to/from deterministic Prolog and built-ins are just "drop-ins",
> one can still develop fast "logic programming" applications by easily
> combining the two languages.
Do I read this as: Prolog for non-determinism, and Scala for
determinism, and heavy interaction between the two?
But I guess you need a low level interface for the heavy interaction,
something that most Prolog systems provide for their implementation
language.
I noticed that a low level interface has one disadvantage besides
it obvious advantage. It can make your interpreter code hard
to change. For example, in Jekejeke Prolog there is a private
invisible low level interface something along (simplified sketch):
my_pred_low_level(Skeleton goalskel, Display goaldisp)
The provider of a low level predicate has to walk the Goal by
himself, and extract the arguments. Also the provider of a
low level predicate has use to use term routines on (skel, disp)
pairs, since this is the current low level term representation.
Now if anything changes in the low level implementation of the
interpreter, for example changes in the term routines etc.. Then
all the low level predicates have to be adapted.
Jekejeke Prolog has also a high level interface, the FFI (Foreign
Function Interface). This is an artificial wrapper, where one
can provide a predicate via:
my_pred_high_level(Term arg1, ..., Term arg2)
The wrapper does a lot of work for the provider of a high level
predicate. For example the walking of the Goal to produce the
Goal arguments is done via reflection. It is also possible to
use other types than Term. Further the Term class is an abstraction
of the (skel, disp) pairs, and provides its own set of routines
which map to the low level routines.
Now if anything changes in the low level implementation of the
interpreter, for example changes in the term routines etc.. Then
all the high level predicates do not have to be adapted.
I guess the above low level/high level is an instance of the
fragile base class problem, where the high level interface is an
attempt to solve the problem for a certain type of clients of
the interpreter.
But I don't see yet how I could eliminate the overhead of the
high level interface. The wrapper is more or less one simple
indirection, but I don't think the JVM can eliminate it. So high
level FFI calls are much more expensive then low level built-in
calls.
I guess the problem could be better solved, in a Jekejni that
would somehow compile the high level predicate definitions into
low level stubs, instead of intrepreting the high level predicate
definitions. Don't know if Scala has some mechanism to somehow
define such translations in the language. This would be an
interesting programming language I would immediately embrace.
Meanwhile the strategy is to avoid heavy use of the high level
FFI, provide some crucial built-ins via the low level interface,
and be happy that the internals of the interpreter can be easily
changed without impacting the applications that use the high level
FFI.
Bye