Expand a query into a list in prolog

笑着哭i 提交于 2020-01-06 05:27:08

问题


How to expand a query into a list?

f(a,b).
f(a,c).
d(a.d).

expand(f(a,X), Out)  -----> Out=[b,c,d]

回答1:


Use bagof/3 or setof/3. E.g.:

?- bagof(X, (X = 1; X = 2), L).

L = [1,2]

yes

In your case that would be

?- bagof(X, f(a,X), Out).



来源:https://stackoverflow.com/questions/1445490/expand-a-query-into-a-list-in-prolog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!