de Boer's Beginners' Guide, section 6.4, help please...
Posted: 12 May 2023 10:18
Hello everyone and greetings from Johannesburg in South Africa.....
Prolog n00b here, but not new to programming, having first learned Fortran at Uni in 1974.
Has anyone worked through the code that Thomas de Boer presents in section 6.4 of his "A Beginners' Guide to Visual Prolog V7.2", or maybe the author even reads this forum?
(Huge thanks to Mr de Boer for putting the book together.)
I get this part at the top of section 6.4...
... which introduces the path:
TheGrandFather is father of ParentOfPerson who is parent of Person, so that ultimately:
TheGrandFather is grandFather of Person.
I also get that that introduces the notion of father and that requires its own predicate to determine fatherhood.
So yes, I then understand both versions of that as presented bottom of page 83 and middle of page 84. (And in fact if you simply query fatherhood, those both work "standalone" so to speak.)
What I don't understand is the code presented at the bottom of page 84 and in the screenshot figure 6.3 where there's an extra "layer" (for want of a better word) compared to the part I quoted earlier:
Previously there were only 3 variables (TheGrandFather, ParentOfPerson and Person) but here there's a fourth (Father). I'm not understanding the link between that grandFather predicate just quoted and this one for father:
I am tearing my (already limited) hair out here, and would really appreciate it if someone could walk me through how the first predicate "calls" the second (if indeed that's happening) and what the passage of the variables is.
Believe me, I have spent a lot of time trying to figure this out.....
Cheers,
Jim
Prolog n00b here, but not new to programming, having first learned Fortran at Uni in 1974.
Has anyone worked through the code that Thomas de Boer presents in section 6.4 of his "A Beginners' Guide to Visual Prolog V7.2", or maybe the author even reads this forum?
(Huge thanks to Mr de Boer for putting the book together.)
I get this part at the top of section 6.4...
Code: Select all
grandFather(Person,TheGrandFather):-
parent(Person,ParentOfPerson),
father(ParentOfPerson,TheGrandFather).
TheGrandFather is father of ParentOfPerson who is parent of Person, so that ultimately:
TheGrandFather is grandFather of Person.
I also get that that introduces the notion of father and that requires its own predicate to determine fatherhood.
So yes, I then understand both versions of that as presented bottom of page 83 and middle of page 84. (And in fact if you simply query fatherhood, those both work "standalone" so to speak.)
What I don't understand is the code presented at the bottom of page 84 and in the screenshot figure 6.3 where there's an extra "layer" (for want of a better word) compared to the part I quoted earlier:
Code: Select all
grandfather(Person,Grandfather) :-
parent(Father,ParentOfPerson),
father(ParentOfPerson,GrandFather).
Code: Select all
father(Person, person(Name, "male")) :-
parent(Person, person(Name,"male")).
Believe me, I have spent a lot of time trying to figure this out.....
Cheers,
Jim