问题标签 [gnu-prolog]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
prolog - 选择重做直到失败,为什么?
我有以下功能:
我通过以下方式使用 trace on 调用它:
我不明白为什么在上面的跟踪中调用了重做。不应该选择“工作”,因此调用的下一行是
有人可以在这里帮助解释重做的外观吗?先感谢您。
prolog - 在 Java 中使用 (nb_)setarg/3 和 gnu.prolog
我目前正在尝试使用 gnu.prolog (http://www.gnu.org/software/gnuprologjava/)从java中使用prolog。
感谢CapelliC的大力帮助,我现在有了一个非常适合我的目的的 prolog 程序。问题是 gnu.prolog 不支持reverse/2
也不支持nb_setarg/3
. Java 会抛出一个错误:
自己实现不是什么大问题,reverse/2
但我不知道如何替换nb_setarg/3
(setarg/3
也不起作用)
这是我的序言代码:
我尝试使用JPL
fromSWI Prolog
但由于严重异常指出 Eclipse 无法正确找到库而无法运行它。我总是得到以下例外之一:
即使遵循此指南和本指南,我也无法解决我的问题。在 Windows(32 位)和 Ubuntu(64 位)上都没有。
您对我有什么解决方案可以让我JPL
跑步或如何使用nb_setarg/3
吗?到目前为止,我花了一天半的时间没有任何结果。相当令人沮丧...
prolog - Prolog在列表错误中找到最小值
我试图让我的代码工作,但不知何故我陷入了一个问题,我是个新手。这是我的代码。
但是当我调用 findMin() 我得到这个错误
未捕获的异常:error(type_error(evaluable,'.'/2),(<)/2)
我真的卡住了,不知道该怎么办。任何帮助将不胜感激。
应用程序的目的是通过调用 shortestPath() 获得最短路径,路径在 dist (a,b,distance)
prolog - gprolog 包含指令不起作用
我在 Fedora 17 Linux 机器上运行 gprolog 1.4.2 版。
我写了一个运行良好的小型 prolog 程序。我在其中定义了一些谓词,我想将它们提升出来并在其他 prolog 程序中使用。所以我想我会把它们放在一个单独的文件中并使用include
指令(在 1.4.2 版 GNU Prolog 手册的第 7.1.8 节中定义)。但是,它没有用。gprolog
说那些谓词(在包含的文件中)是未定义的。
所以在 gprolog 提示符下我输入:
我得到:
所以它显然不能识别指令。我已经搜索了所有内容,但找不到发生这种情况的任何原因。对此有什么想法吗?
prolog - GNU Prolog 中的错误
我有这个代码:
我得到这些错误:
e.pl:1:2: 语法错误: . 表达式 e.pl:5:2: 语法错误之后需要的或运算符:。或表达式后预期的运算符
你能告诉我这段代码有什么问题吗?
prolog - 制作适用于 GNU 和 SWI 的 Prolog 代码
我意识到这会有限制,但是有没有一种合理的方法可以在 Prolog 代码中放入条件指令,以便它在 GNU 或 SWI 中合理地工作?sumlist
我在考虑至少最简单的情况,即SWI 和GNU中的内置谓词sum_list
在拼写上不匹配。或者 SWI 有assert
但 GNU 没有。所以最好有类似的东西:
或者简单地说:
或者什么不是。两种语言中都存在条件指令,但似乎没有提供执行此类操作所需的条件。我可能遗漏了一些手动搜索没有出现的东西。
prolog - What does it mean when gprolog says "true?" instead of "yes" in this instance?
I am attempting to write a gprolog program that affirms that, given some "reasonable" background from this song (listen here :-) ), will answer yes when I query grandpa(me, me)
(i.e., Am I indeed my own grandpa?). This was given as an assignment for my AI class, and we were left to decide for ourselves what facts and predicates to include. Though it's full of redundancy and some clauses that I don't use (some just for the sake of the song), here is what I threw together, with the necessary assumption that step-children are considered to be full/general children:
It's sloppy, but I'd say the most important things are clauses 13 and 14. In particular, 14 attempts to ensure that, for example, my dad is my child since he married my stepchild and is thus my son-in-law.
Anyway, a trace shows that running the query seems to work--kind of:
My concern is with the true?
statement. If I just press enter, the yes
appears, but saying something like a
leads to an infinite loop, with the call stack getting a little bigger and bigger each round before "true" appears again. What is going on here? I thought that a successful 'confirmation' of the query would mean the end of things. I don't see any more variables to check!
prolog - gprolog - Simple way to determine whether one list is a permutation of another
I'm trying to write a prolog program that determines whether one list is a permutation of another. Input is of the form perm(L,M)
, which will be true if and only if list L
is a permutation of list M
.
This is for my AI class, so I cannot just use the nifty little permutation
predicate that gprolog already provides. Our professor noted that the member
predicate might be useful, but any ideas I have that involve it seem to require very tricky and not-so-declarative things (and I'm assuming there is a way to solve this without getting too advanced, since the class is new to prolog.)
Anyway, one way to check would supposedly be to see that L
and M
are the same size, each L
element is in M
, and each M
element is in L
(there's a use of member
!). However, this wouldn't be enough for cases like [2,2,4]
and [4,4,2]
, among others.
Another way could be to ensure that the same counts of each element are in the opposite list, but my impression of prolog is that any kind of variable 'memory' is rather difficult business (in fact, it seems that the example programs I see that perform sorts, etc., aren't really manipulating data at all; they're just 'hypothetically' rearranging things and then telling you yes or no...?)
Mentally, one could just sort both lists and check elements side-by-side, but that, among tons of other ways to think of it, seems a little too object-oriented...
Any hints? My biggest trouble seems to be (as mentioned) the fact that doing "operations" seems to be more like asking about them and hoping that things stay true long enough to get where you want.
**UPDATE: gprolog does offer a delete
functionality, but it comes with the declarative-related trouble I was expecting, given an attempt like this:
perm([LH|LT], R) :- member(LH,R), delete([LH|LT],LH,R), perm(LT,R).
In the manual, delete is defined like this: "delete(List1, Element, List2) removes all occurrences of Element in List1 to provide List2. A strict term equality is required, cf. (==)/2"
Execution:
**UPDATE 2: I think I might have figured it out! It's kind of verbose, but I have tested it for quite a few cases and haven't found a bad one yet. If someone sees a major issue, please point it out:
I do like the cut operator..
prolog - Prolog:比较一系列时间
简而言之,prolog 程序 (GNU Prolog) 的基本思想是搜索一个数据库,其中包含在一组时间(开始时间、结束时间)内有可用时间段的人,并返回在该时间段内第一个可以见面的人。输入具有语法
我有一个与上述匹配的谓词:
并且数据库条目如下所示:
我卡住的地方是我不确定如何将数据库中的时间与调用我的会议谓词时输入的时间进行比较。不是在寻找免费的答案,只是想要一个正确的方向和一个很好的例子:) 谢谢大家!
prolog - GNU Prolog:显示 WAM 代码进行查询?
是否可以使用GNU Prolog显示查询的 WAM 代码?
我知道我可以使用 pl2wam 为程序生成 WAM,但是我对程序执行的查询呢?有没有办法为此显示 WAM 代码?
我正在为 x64 Windows 使用 1.4.4 版