我在prolog中实现Family程序我有一个问题就是实现一些规则。
首先,我实施此规则:
number_of_children_couple(_list):-
findall(children(_f,_m,_n),children(_f,_m,_n),_list).
返回列表:
19 ?- number_of_children_couple(_list).
_list = [children(mordechai, miriam, 1), children(salax, naima, 1), children(eli, bella, 2), children(..., ..., ...)|...].
我的问题是如何实施:
number_of_children_person(_list28,list_person):-
第一个论点:
_list28 = _list //the above list ,that return from the rule
,第二个参数是:
list_person = [children(mordechai, 1), children(salax, 1),children(eli, 2),children(..., ...)|...]
我也用:
%_num is number of children for couple
children(_father,_mother,_num):-
couple(_mother,_father),
findall(_child,parents(_mother,_father,_child),_children),
length1(_children,_num).
%_ num是_person
的子项数children(_person,_num):-
gender(_person,_),
findall(_child,parent(_person,_child),_list),
length1(_list,_num).
答案 0 :(得分:0)
如果你想要的是从children / 3结构中删除一个参数,可以通过多种方式完成,更简单的是
number_of_children_person([],[]).
number_of_children_person([children(A,_,C)|R],[children(A,C)|T]) :-
number_of_children_person(R,T).
或更多succintly
number_of_children_person(L3,L2) :-
findall(children(A,C), member(children(A,B,C),L3), L2).