[英]Add to list in prolog
In the exercise the first thing I need is to get some facts, stating the existence of one place each, into a list. 在练习中,我需要做的第一件事是获取一些事实,将每个地方的存在声明为一个列表。 Someone help me please.
请有人帮我。
example.
exists(place).
exists(place2).
Code so far: 到目前为止的代码:
listarB([]).
listarB([B|T]):- exists(B),listarB(T).
Now I tried to get a list of lists. 现在,我尝试获取列表列表。 Each list I need is held as an argument of each of the places i was trying to get.
我需要的每个列表都作为我尝试获取的每个位置的参数。
Now that I have the list of places I tried to get the lists each of them has as an argument and store them in another list([HL|TL]) 现在,我有了一个地点列表,我试图获取每个地点的列表作为参数并将它们存储在另一个列表中[[HL | TL])
Code so far: 到目前为止的代码:
listListBus([],[]).
listListBus([HB|TB],[HL|TL]) :-
HB = base(_,[_|_],HL),
listListBus(TB,TL).
You should use findall/3
to collect all the places that "exist": 您应该使用
findall/3
来收集所有“存在”的位置:
listarB(L):-
findall(B, exists(B), L).
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.