gpt4 book ai didi

c - 从 C 独立调用 (GNU) Prolog 的示例

转载 作者:太空宇宙 更新时间:2023-11-04 04:41:34 27 4
gpt4 key购买 nike

我想构建一个基于 C 文件的可执行文件,其中使用了 Prolog 谓词。我想使用 GNU Prolog。

我成功(基于 gnu prolog 教程)构建了 examp_c.c、examp.pl:

#include <string.h>
#include <gprolog.h>

PlBool
my_call(PlTerm goal)

{
PlTerm *arg;
int functor, arity;
int result;

arg = Pl_Rd_Callable_Check(goal, &functor, &arity);
Pl_Query_Begin(PL_FALSE);
result = Pl_Query_Call(functor, arity, arg);
Pl_Query_End(PL_KEEP_FOR_PROLOG);
return (result == PL_SUCCESS);
}

编译使用

gplc examp.pl examp_c.c

当调用可执行示例时,Prolog 解释器被启动/模拟:

GNU Prolog 1.4.4 (64 bits)
Compiled Aug 3 2013, 20:06:22 with gcc
By Daniel Diaz
Copyright (C) 1999-2013 Daniel Diaz
| ?-

但我想要的是有一个 C 程序在内部调用 Prolog,而不通过 Prolog 解释器与用户通信。 Prolog 谓词应作为 C 程序的参数/在 C 程序内提交,或者在内部生成。

你知道这方面的例子吗?还是我误解了什么,这不可能吗?

你看,我刚开始是新手...我很乐意得到一些帮助 :-) 非常感谢。

最佳答案

您也可以直接在 C 中编写一个 main(),然后从 C 中调用 Prolog。 See Defining a new C main function in the manual.

关于c - 从 C 独立调用 (GNU) Prolog 的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25937690/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com