mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
1.99k stars 116 forks source link

To think about codegeneration #137

Open XVilka opened 5 years ago

XVilka commented 5 years ago

It is not exactly a feature request, more like a food for thought. It might be applicable to the Scryer Prolog, and might be not. One of the popular cases to use logic programming - using just a "subset" of Prolog - Datalog. And quite often - just generating the efficient native code based on these rules. One of the examples is Souffle Language (GitHub repo). But it processes its own superset of Prolog. And it generates C++ code as an output. I just thought one of the possible cases (maybe just some subset of the ISO Prolog) would be generating Rust code instead. Thanks for reading up to this point.

image

For example rule like

C(X,Z) :- A(X,Y), B(Y,Z).

is translated into a loop nest similar to

for( e1 : A ) {
    for( e2 : B ) {
        if ( e1[1] == e2[0] ) {
            C.insert( e1[0], e2[1] );
        }
    }
} 
UWN commented 5 years ago

This is an entirely different project

stefan-kral commented 4 years ago

I do not see how this information could be of any practical use for implementing a Prolog system.

From an implementor's viewpoint, this kind of code is miles away from where it's at.