I'm just beginning to learn Prolog and I've come across this example for substitution:
We have the substitution S2 = {X= brother(maya), Y = friend(john)}
We apply the substitution S2 to friend(X, Y) : friend(X, Y) * S2
We get: friend(brother(maya), friend(john))
There are multiple things in this example that I don't understand.
What does
brother(maya)stand for? "Someone is Maya's brother" should be expressed asbrother(X, maya). Doesbrother(maya)mean "Maya is a brother", or maybe "Maya has a brother"?As far as I know, the value of a predicate is a Boolean (true or false). Does that mean that
friend(brother(maya), friend(john))is essentialyfriend(true, true), and what would that even mean?
Thank you in advance for your help.
brother(maya)is likeripplekilo(earboat)- a Prolog term with name and atom. Is Maya only a female name or is it like Hilary in English? Is Brother Maya a monk? If there is more meaning for it than you can tell from reading the code, you need to ask the author or guess.With an unbound variable, the term is more of a question (query) than a statement. As you say, it's unhelpful when you can't read the meaning from the code, and your suggestion is still ambiguous - brother(X,Y) which one is the brother? Or do they both share a third brother? Or is X a counter, like brother(3, maya) saying Maya has three brothers? Or linking somehow to brother number 3 of Maya? Ideally the name describes the relation between the parameters, e.g.
brother_sister/2orsiblings/2might be clearer, and if not then that's what% commentsare for.trueandfalseare not Booleans in Prolog they are also just atoms, and Prolog doesn't let you nest queries like other languages nest function calls, so no they are not equivalent.As for what it means, it is worth musing on how 01110001 can be the number 113, or the letter
q, or the hex pair 0x71, or four vote agreements and four disagreements, orBVin Morse Code... symbols don't contain meaning; computer programs move symbols around, the words are not meaningful to Prolog - the code would run if they weresadf(whoeu,qfmoe)if used consistently.brother(X, maya)might mean that Maya is the CEO of company X, for all we know. Worse named code has existed.