如何在序言中获取1999年之前出生的所有孩子的名字
how to get the first name of all childs who are born before 1999 in prolog
我有这个数据库,我写了查询,它给我丈夫、妻子和 child 的所有信息,我是如何得到所有 child 出生在 1999 年之前的 [=13] =]在一个列表中?
family(
person(tom,fox,date(7,may,1960),work(cnn,15200)),
person(ann,fox,date(9,may,1961),unemployed),
[person(pat,fox,date(5,may,1983),unemployed),
person(jim,fox,date(5,may,1985),unemployed)]).
family(
person(nom,ros,date(30,may,1976),work(abc,16200)),
person(shi,ros,date(22,july,1981),work(cbs,19000)),
[person(mat,ros,date(5,aug,2005),unemployed),
person(har,ros,date(5,jan,2007),unemployed),
person(teh,ros,date(20,aug,2011),unemployed)]).
family(
person(zvi,ha,date(21,jan,1980),work(cnn,11200)),
person(haya,shu,date(19,aug,1979),work(fox,15000)),
[person(isi,ha,date(15,aug,1987),unemployed),
person(riv,ha,date(3,jan,2011),unemployed)]).
husband(X):-family(X,_,_).
wife(X):-family(_,X,_).
child(X):-family(_,_,Children),member(X,Children).
试试这个:
dateofbirth(person(_,_,Date,_), Date).
child1999(X, L) :-
child(X),
dateofbirth(X, date(_,_,Y)),
Y < 1999.
我有这个数据库,我写了查询,它给我丈夫、妻子和 child 的所有信息,我是如何得到所有 child 出生在 1999 年之前的 [=13] =]在一个列表中?
family(
person(tom,fox,date(7,may,1960),work(cnn,15200)),
person(ann,fox,date(9,may,1961),unemployed),
[person(pat,fox,date(5,may,1983),unemployed),
person(jim,fox,date(5,may,1985),unemployed)]).
family(
person(nom,ros,date(30,may,1976),work(abc,16200)),
person(shi,ros,date(22,july,1981),work(cbs,19000)),
[person(mat,ros,date(5,aug,2005),unemployed),
person(har,ros,date(5,jan,2007),unemployed),
person(teh,ros,date(20,aug,2011),unemployed)]).
family(
person(zvi,ha,date(21,jan,1980),work(cnn,11200)),
person(haya,shu,date(19,aug,1979),work(fox,15000)),
[person(isi,ha,date(15,aug,1987),unemployed),
person(riv,ha,date(3,jan,2011),unemployed)]).
husband(X):-family(X,_,_).
wife(X):-family(_,X,_).
child(X):-family(_,_,Children),member(X,Children).
试试这个:
dateofbirth(person(_,_,Date,_), Date).
child1999(X, L) :-
child(X),
dateofbirth(X, date(_,_,Y)),
Y < 1999.