我写了 4 个家庭列表和一些规则,如下所示:
family(
person( tom, fox, date(7,may,1960), works( bbc, 15200)),
person( ann, fox, date(9,may,1961), unemployed),
[ person( pat, fox, date(5,may,1983), unemployed),
person( jim, fox, date(5,may,1983), unemployed) ] ).
family(
person( chris, adler, date(1,jan,1965), works( rekit, 23000)),
person( mary, adler, date(7,apr,1968), works( dia, 9500),
[ person( john, adler, date(19,apr,1995), unemployed),
person( randal, adler, date(22,nov,1992), unemployed) ] ).
family(
person( james, gordon, date(23,aug,1953), works( GCPD, 17000)),
person( kristen, gordon, date(22,may,1955), works( Hospital, 15000),
[ person( penny, gordon, date(2,dec,1995), unemployed),
person( george, gordon, date(2,dec,1995), unemployed),
person( nick, gordon, date(15,sep,1993), unemployed) ] ).
family(
person( bilbo, baggins, date(7,may,1980), works( farmer, 19200)),
person( beladona, baggins, date(9,sep,1971), works( farmer, 18200)),
[ person( frodo, baggins, date(15,jun,1995), unemployed),
person( sam, baggins, date(25,may,1993), unemployed) ],
person( mery, baggins, date(9,mar,1992), unemployed),
person( pippin, baggins, date(17,dec,1998), unemployed), ).
family(
person( ragnar, lothbrok, date(7,may,1970), works( WarIN, 19500)),
person( lagertha, lothbrok, date(9,may,1971), unemployed),
[ person( rolo, lothbrok, date(5,may,1995), unemployed),
person( bjorn, lothbrok, date(5,may,1983), unemployed) ] ).
husband( X) :- family( X, _, _).
wife( X) :- family( _, X, _).
child( X) :- family( _, _, Children), member( X, Children).
exists( Persons) :- husband( Persons); wife( Persons);
child( Persons).
dateofbirth( person(_, _, Date, _), Date).
问题是当我问一个问题时:
?- child( X), dateofbirth( X, date( _, _, 1995)).
结果我得到了最后一个家庭的孩子,而不是他们四个。
X = person(rolo, lothbrok, date(5, may, 1995), unemployed) ;
false.
有什么帮助吗?