prolog - Querying each element of a list -


i doing homework ai class , writing prolog program.

i supposed take list of names , check if each person in list belongs specific country chosen.

what have far

% facts person(bruce, australia, rhodri, bronwyn). person(rhodri, newyork, dan, mary). person(bronwyn, miami, gar, roo). person(dan, miami, george, mimi). person(mary, texas, mack, tiki). person(gar, jamaica, zid, rem). person(roo, newzealand, john, jill).  person(tom, mayday, dick, mel). person(dick, newyork, harry, rin). person(mel, miami, tom, stacey). person(harry, miami, george, mimi). person(rin, texas, mack, tiki). person(tom, jamaica, zid, rem). person(stacey, newzealand, john, jill).  % rules  eligible(p,c) :-    person(p, c, f, m) , !  ; person(f, c, newfather, newmother), !  ; person(m, c, newfather, newmother), !  ; person(newfather, c, grandfather , grandmother), !  ; person(newmother, c, grandfather, grandmother).  checkteam([] , c).  checkteam([h|t] , c) :- eligible(h, c) , checkteam(t, c). 

the last 2 lines in particular having issues with, trying test each member of list eligible() function let first element of tail become head , repeat.

i cant figure out way test each member , display fail if of members not eligible or true if members belong country.

thanks in advance.

edit: fooling around , changed code little, results

?- checkteam([bruce, dan], mayday). true. 

even though neither bruce or dan mayday or parents or grandparents do.

your eligible predicate doesn't make sense me (probably misunderstanding). but, if person defined person(name, country, father, mother) be:

eligible(name, country) :- person(name, country, _, _). eligible(name, country) :- person(name, _, father, _),                            person(father, country, _, _). eligible(name, country) :- person(name, _, _, mother),                            person(mother, country, _, _). 

then checkteam should still give warning. put underscore @ beginning of variable name rid of it:

checkteam([], _country). 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -