Linux g++在 C++ 中嵌入 Prolog 逻辑引擎
我在 C++ 程序中的一些逻辑不仅非常复杂,而且需要多种解决方案,而 Prolog 是理想的选择。它有点像防火墙配置脚本,检查操作的输入,但有时需要不止一项操作。
我想要的是这样的:
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.
};
它不需要回调 C++ 的能力。
AMI Prolog 似乎可以使用它,但它在 Linux 上不可用。我正在尝试使用 SWI-Prolog,但只能找到 2 个示例和令人难以置信的拜占庭 API(我的意见)
任何人都可以向我指出一个与我正在寻找的内容接近的示例吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SWI-Prolog 的 C++ 接口,这是高级别的。
我正在与之斗争,这里有一个桥接 OpenGL 的示例:
这段干净的代码使用隐式类型转换和一些宏隐藏了许多“bizantinism”。该接口非常强硬且双向:要从 C++ 调用 Prolog,可以使用 PlCall(“运行”查询,类似于评估您在答案中公开的内容)或更结构化的 PlQuery,以获得多个结果...
如果您不需要要链接到 openGl,或者可以等待我希望从 SWI-Prolog 邮件列表中得到的答案,您应该对其进行评估。
There is A C++ interface to SWI-Prolog, that's high level.
I'm fighting with it, here an example of bridging to OpenGL:
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.
如果您不介意重写 prolog 代码以在本机 c++ 头文件库中使用,我会研究 Castor 库:
http://www.mpprogramming.com/cpp/
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/