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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -