问题标签 [prolog-setof]
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.
recursion - Prolog Find All Predicate
I am trying to find all the brothers of a person.. I have created the following rule..
This works however, if a person has more then one brother then it will only find a single brother.. I'm assuming I have to use recursion somehow but I'm a little stuck!
prolog - 在 prolog 中使用自创列表
我对 Prolog 很陌生,不要对我太苛刻。无论如何,我在 Prolog 中遇到了下一个问题:
我创建了一个小型演员“数据库”,定义为:
电影、演员、导演也是如此,定义为:
现在我需要编写一个程序 people(Movie, List) 来定义电影名称和参与电影的所有人的姓名列表之间的关系 - 导演和演员(以任何顺序)。
所以我开始了:
所以上面所做的就是回答给定的列表是否在那部电影中扮演[或导演]。[但它也有一个问题,因为不包含所有演员的列表仍然会得到“真实”。]
无论如何,我对我的解决方案进行了更多思考,并且我认为这在逻辑上不是解决该问题的完美方法[这就是我没有完成它的原因]。
我想过尝试另一种方法,它是通过逻辑地问:我实际上需要回答什么?
答案是:是否有一个列表,以便将电影中的演员列表附加到导演[只有一个]等于它。
但现在我几乎被困住了。我如何在 Prolog 中使用自己创建的列表?获取演员列表很简单,只需执行以下操作:
但是我怎样才能使用函数定义的答案呢?[我什至可以这样做吗?] 或者我应该再次尝试改变我的方法吗?
eclipse - 如何避免 SICStus SPIDER 中的元参数警告?
这可能与comp.lang.prolog-discussion 有关。
在使用带有 SICStus SPIDER 的 Eclipse 时,我收到了几个这样的警告:
这是一个代码示例:
如何摆脱 SPIDER 警告?我对简单地抑制警告并不感兴趣。我正在使用最新版本的 SPIDER IDE (0.0.51) 和 SICStus Prolog 4.2.3。
variables - Correct use of findall/3, especially the last result argument
I'm a beginner in Prolog and I am dealing with a problem that might seem stupid to you, but I really can't understand what I'm doing wrong! Ok, I have this file fruits.pl and inside that I have something like this:
I have already (inside that file made a coexist(X,Y) atom that checks if two fruits can be put together in a plate. It works fine! But now I can't create a suggest(X) that takes as a parameter a fruit and returns a list of fruits that can be put together in the same plate. The thing is I was trying to make something like that
What do you think? Every time I try to run this in swi prolog there is a warning 'singleton variable' and when I press
then it says false.. sorry for my english :/
xml - 在 GOAL 中使用 setof/3 和递归调用会出错,为什么?
我在使用时遇到问题setof/3
,缺少一些结果。
上下文:
我使用 SWI-Prolog load_xml() 加载一个 xml 文件以获取递归列表元素(参见示例中的 testelement)。然后我想在这个列表中查找特定的元素(在 xml 树中)。结合使用
,效果很好。但如果我使用,我会错过一个结果。我想这是由于递归调用获取/保留元素而导致的问题?知道将元素从递归列表中取出的另一种解决方案吗?findall/3
sort/2
setof/3
setof/3
askElement/3
我的测试代码:
我的输出:
我希望在这两种情况下我都能得到
怎么了?
提前谢谢了!
PS:非常欢迎对我(第一次尝试)Prolog 代码的每条评论/评论:}
prolog - 每次返回列表的集合,prolog
我正在使用如下所示的谓词:
我的问题是我的代码为每个值返回列表 X。我想要的是返回一个包含所有数字的大列表,因为现在我得到了答案:
因此,每次我想要一个包含所有内容的大列表时,而不是小列表。
编辑评论 ----------
这是我写的,它立即给了我错误。
prolog - 协助编写 Prolog 规则
鉴于我已将以下事实输入事实库。每个sideish有两种成分:
我写了以下规则来返回给定假期的菜肴:
我正在尝试编写一个规则,该规则ingredientList
将确定每个假期所需的成分类型。通过关联每个给定假期的菜肴和配料。
prolog - 从谓词中收集所有“最小”解决方案
鉴于数据库中的以下事实:
我想收集所有具有最小第二个参数的第一个参数,加上第二个参数的值。第一次尝试:
而不是setof/3
,我可以使用aggregate/3
:
注意
如果我正在寻找数字的最小值,这只会给出相同的结果。如果涉及算术表达式,结果可能会有所不同。如果涉及非数字,aggregate(min(...), ...)
将抛出错误!
或者,相反,我可以使用完整的键排序列表:
最后,对于问题:
我可以直接使用库(聚合)吗?感觉应该是可以的......
或者是否有
std::partition_point
来自 C++ 标准库的谓词?还是有一些更简单的方法可以做到这一点?
编辑:
为了更具描述性。假设有一个(库)谓词partition_point/4
:
(我不喜欢这个名字,但我们现在可以忍受)
然后:
prolog - 为什么 swi-prolog 中的 findall/3 忽略变量绑定?
以下代码给出了这些结果:
但是,当我希望所有元素都共享相同的未绑定变量(而不是 a)时,事情就不会像预期的那样工作:
为什么 _G1918、_G1912 和 _G1906 不相互绑定?这是 swi-prolog 中的错误吗?