Linux g ++ Embedding the Prolog Logic Engine in C ++

I have some logic in a C ++ program that is not only insanely complex, but also requires several solutions for which Prolog is perfect. This is similar to a firewall script configuration, checking for action input, but sometimes more than one action is required.

I want something like this:

class PrologEngine { LoadLogic(const char* filename) throw PrologException; // Load a file of prolog rules, predicates facts etc in textual format. Must be callable multiple times to load AND COMPILE (for speed) prolog rule files. std::vector<std::string> Evaluate(const char* predicate_in_string_form = "execute(input, Result)") throw PrologException; Returns a vector of matching predicates in text form. }; 

It does not need the ability to call back to C ++.

AMI Prolog seems to have got it, but it is not available on Linux. I am trying to use SWI-Prolog and can only find 2 examples and an incredibly Byzantine API (my opinion)

Can someone give me an example close to what I'm looking for?

+4
source share
2 answers

There is a C ++ Interface for SWI-Prolog , this high level.

I'm fighting it , here is an example of connecting to OpenGL:

 PREDICATE(glEvalCoord1d, 1) { double u = A1; glEvalCoord1d( u ); return TRUE; } 

This clean code hides a lot of β€œbyzantism,” using implicit type conversions and some macros. The interface is well simple and bidirectional: to call Prolog from C ++ there is PlCall (β€œrun” a request similar to the one you evaluate in response) or a more structured PlQuery for several results ...

If you do not need to link to openGl or you can wait to hear the answer, which I hope I will get from the SWI-Prolog mailing list, you should evaluate it.

+4
source

If you do not mind rewriting the prolog code to use only the C ++ header in the native library, I would look into the castor library: http://www.mpprogramming.com/cpp/

+3
source

Source: https://habr.com/ru/post/1396667/


All Articles