Prolog - 如何将数据从数据库(断言)传递到列表中?

时间:2015-04-27 19:31:14

标签: prolog

基本上,我使用tokenHeader = 'Bearer ' + authData.token; var uploader = $scope.uploader = new FileUploader({ headers: { "Authorization": tokenHeader }, url: _uploadUrl, withCredentials: true }); 声明了几个结构。

可以通过查询assert列出此数据库,并打印出类似(在控制台中)的内容:

listing(myData).

我想知道是否有一种方法可以创建一个"返回"包含所有这些元素的列表。

所以我应该能够拥有一个animal(cat) animal(bird) animal(human) animal(elephant)

形式的列表

提前致谢。 (请不要问我为什么要这样做)

1 个答案:

答案 0 :(得分:0)

这里有一个小例子,演示bagoffindall与各种生成器的用法:

:-initialization(main).

animal(cat).
animal(bird).
animal(human).
animal(elephant).

main :- 
  write("bagof animal(_)      : "),bagof(animal(X), animal(X), Bag), write(Bag), nl,
  write("bagof generator(42,_): "),bagof(generator(42, Y), animal(Y), Bag2), write(Bag2), nl,
  write("bagof _              : "),bagof(Y, animal(Y), Bag4), write(Bag4), nl,
  write("findall gen(35,_)    : "),findall(gen(35, Z), animal(Z), Bag3), write(Bag3), nl,
  halt.

输出:

bagof animal(_)      : [animal(cat),animal(bird),animal(human),animal(elephant)]
bagof generator(42,_): [generator(42,cat),generator(42,bird),generator(42,human),generator(42,elephant)]
bagof _              : [cat,bird,human,elephant]
findall gen(35,_)    : [gen(35,cat),gen(35,bird),gen(35,human),gen(35,elephant)]