查找所有值

Finding all values

我是 prolog 世界的新手,目前在学校项目中遇到一个问题。 我有事实:

family (
    person(_,_,_,_), %father
    person(_,_,_,_), %mother
    []). %array with children

前三个字段是姓名、姓氏和 date_of_birth,第四个字段可以是:unemployedbenefitemployed(Name_of_company, Salary)。我也有谓词:

exists(Person) % I think that implementation is irrelevant, means that person is in DB
salary(person(_,_,_,unemployed),0).
salary(person(_,_,_,benefit,500).
salary(person(_,_,_,employed(_,S)),S).

这就是作为练习的一部分给出的所有事实和谓词。我想提取所有人员薪水的清单。 我试过类似的东西:

findall(X,salary(_,X),L). % it doesn't search people and returns fixed 3 values

exists(Y),
findall(X,salary(Y,X),L). %however it returns value for each person instead of combined list

我完全不知道该怎么做。谁能帮帮我?

exists(Y),
findall(X,salary(Y,X),L). 
  %however it returns value for each person 
  %instead of combined list

也应该如此。如果你想要组合列表(我假设,数据库中所有人的人薪列表),你应该创建一个命名规则来查找一个人的薪水,并使用 itfindall.

但另一方面,为什么上面的查询中有 findall?就好像您期望某个人有几份薪水。肯定只有一个。在这种情况下,查询应该只是

findall( Y-X, ( exists(Y), salary(Y,X) ), L).