Linux g++在 C++ 中嵌入 Prolog 逻辑引擎

发布于 2025-01-06 11:18:04 字数 714 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听风吹 2025-01-13 11:18:04

SWI-Prolog 的 C++ 接口,这是高级别的。

我正在与之斗争,这里有一个桥接 OpenGL 的示例:

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

这段干净的代码使用隐式类型转换和一些宏隐藏了许多“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:

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.

撕心裂肺的伤痛 2025-01-13 11:18:04

如果您不介意重写 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文