Putting this in a predicate and returning only the desired values is all that is left to get this query working as desired.Ī correct answer for nephew/2 is nephew(Nephew,Aunt_uncle) :-Įxample run: ?- nephew(Nephew,Aunt_uncle). While this query gives more information than is needed, the correct values are in the results. ?- sibling(Parent,Aunt_uncle),son(Nephew,Parent). When renaming variables, start at the facts and work back, do not start at the head of a clause and work down.Īnother way that helps to figure out problems with multi-statement predicates is to run parts of them as separate queries, e.g. You will see that sibling/2 and son/2 are correct and should see your problem with nephew/2. However if you rename your variables so that they are easier to comprehend sibling(Child_a, Child_b) :. Nephew(X,Y) you would get ?- nephew(X,Y).
0 Comments
Leave a Reply. |