5

I have some logic in a C++ program that is not only insanely complex, it requires multiple solutions for which Prolog is ideal. It's sort of like a firewall config script, checking input for actions, but sometimes more that one action is required.

What I want is 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 needs no ability to call back into C++.

AMI Prolog seems to get it, but it's not available on Linux. I'm trying to use SWI-Prolog and can only find 2 examples and and incredibly byzantine API (my opinion)

Can anyone point me to an example that is close to what I'm looking for?

Walt Howard
  • 7,676
  • 1
  • 16
  • 11
  • This blog post has a small example of what you want to do wit swi-prolog: http://electricbacon.wordpress.com/2010/09/08/calc-example-using-swi-prolog-and-c/ – HaskellElephant Feb 15 '12 at 16:46
  • Why not use CLIPS instead of prolog? http://clipsrules.sourceforge.net/WhatIsCLIPS.html – devil Dec 03 '12 at 02:16

2 Answers2

4

There is A C++ interface to SWI-Prolog, that's high level.

I'm fighting with it, here an example of bridging to OpenGL:

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

This clean code hides many 'bizantinism', using implicit type conversion and some macro. The interface is well tought and bidirectional: to call Prolog from C++ there are PlCall ('run' a query, similar to Evaluate you expose in the answer) or a more structured PlQuery, for multiple results...

If you don't need to link to openGl, or can wait to ear about the answer that hopefully I'll get from SWI-Prolog mailing list, you should evaluate it.

Community
  • 1
  • 1
CapelliC
  • 59,646
  • 5
  • 47
  • 90
3

If you don't mind rewriting the prolog code for use in a native c++ header only library, I'd look into the castor library: http://www.mpprogramming.com/cpp/

shuttle87
  • 15,466
  • 11
  • 77
  • 106