我如何使这个谓词发挥作用?提取的知识(源列表,提取列表)
我有这样的断言:我似乎无法开始工作。 谓词应按以下方式使用:为谓词提供一个事物列表 (KnowledgeList) 和一个未实例化的变量 (ExtractedList)。 然后谓词应该继续填充 ExtractedList。 为了填充 ExtractedList,它迭代 KnowledgeList 的项目, 构建一个新的提取内容列表,并将该列表附加到 ExtractedList。
我知道我可能应该使用递归来解决这个问题,但我现在感到很困惑。
extractedKnowledge(KnowledgeList, ExtractedList) :-
list(KnowledgeList),
ExtractedList = [],
length(KnowledgeList,ListLength),
for(X,1,ListLength),
nth(X,KnowledgeList,ListElement),
...?
I have this predicate that I can't seem to get to work.
The predicate should be used the following way: You give the predicate a list of things (KnowledgeList), and an uninstantiated variable (ExtractedList).
The predicate then should proceed filling ExtractedList.
To fill ExtractedList it iterates over the items of KnowledgeList,
builds a new list of extracted things, and appends this list to ExtractedList.
I know I should probably use recursion to solve this, but I feel stumped at the moment.
extractedKnowledge(KnowledgeList, ExtractedList) :-
list(KnowledgeList),
ExtractedList = [],
length(KnowledgeList,ListLength),
for(X,1,ListLength),
nth(X,KnowledgeList,ListElement),
...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您将
ExtractedList
统一为[]
,因此它将始终为空。你确实应该使用递归。这是一个可以帮助您入门的骨架递归程序:Since you unify
ExtractedList
which[]
, it will always be empty. You should indeed use recursion. Here's a skeletal recursive program to get you started: