Discussions related to Visual Prolog
JimboZA
Posts: 4
Joined: 12 May 2023 9:44

de Boer's Beginners' Guide, section 6.4, help please...

Unread post by JimboZA »

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...

Code: Select all

grandFather(Person,TheGrandFather):-     parent(Person,ParentOfPerson),     father(ParentOfPerson,TheGrandFather).
... 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:

Code: Select all

grandfather(Person,Grandfather) :-     parent(Father,ParentOfPerson),     father(ParentOfPerson,GrandFather).
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:

Code: Select all

father(Person, person(Name, "male")) :-     parent(Person, person(Name,"male")).
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
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Re: de Boer's Beginners' Guide, section 6.4, help please...

Unread post by Harrison Pratt »

I think you found a typographic error. This makes more sense:

Code: Select all

    grandfather(Person, Grandfather) :-         %   parent(Father, ParentOfPerson), % <== error         parent(Person, ParentOfPerson),         father(ParentOfPerson, GrandFather).
JimboZA
Posts: 4
Joined: 12 May 2023 9:44

Re: de Boer's Beginners' Guide, section 6.4, help please...

Unread post by JimboZA »

Hi Harrison, and thanks for the reply.

I'd agree with you if the "wrong" code didn't actually work.... That it works says to me that it's right, and that there's a subtlety that I'm missing.

That said, I'll try it like you said, and see if it works too, and report back tomorrow.

Jim
JimboZA
Posts: 4
Joined: 12 May 2023 9:44

Re: de Boer's Beginners' Guide, section 6.4, help please...

Unread post by JimboZA »

Seems both versions work with identical output. Now I am very very confused. Does anyone have the time and inclination to test this in PIE independently?

Author de Boer says that his chapter 6 ...
is a slight remake of the tutorial Fundamental Prolog (Part 2) by Sabu 8 Francis (Tangential
Solutions) and Thomas Linder Puls (PDC)
... so if either of the latter could comment that would be nice.

Here's the code, including the query and the output as a comment at the end:

Code: Select all

% de Boer section 6.4   parent(person("Bill","male"),person("John","male")). parent(person("Pam","female"),person("Bill","male")). parent(person("Pam","female"),person("Jane","female")). parent(person("Jane","female"),person("Joe","male")).   grandfather(Person,Grandfather) :-     parent(Father,ParentOfPerson),          % as in de Boer's book figure 6.3     %parent(Parent,ParentOfPerson),       % forum suggestion     father(ParentOfPerson,GrandFather).   father(Person, person(Name, "male")) :-     parent(Person, person(Name,"male")).   /* The query as given in book: grandFather(person("Pam","female"),W).   The response (with either code), and as given in the book:   W = person("John","male"). W = person("Joe","male").   */  
JimboZA
Posts: 4
Joined: 12 May 2023 9:44

Re: de Boer's Beginners' Guide, section 6.4, help please...

Unread post by JimboZA »

Aaaaand further to the above, I checked the source that de Boer based his chapter on and it uses only the 3 variables not 4, so perhaps using "father" as a 4th variable is indeed a typo in de Boer's version? (Edit: or maybe it was introduced on purpose, for a reason I have yet to fathom.)

https://wiki.visual-prolog.com/index.ph ... log_Part_2

(Not sure why it works though, but right now I'm not going to lose any sleep over it.)
Post Reply