First off, I am new to Prolog, so please go easy on me... Also, I am using SWI-Prolog, so I want to use the correct syntax for SWI.
In this case, I want to define step-parents (specifically step-mother and step-father). My current syntax is this:
isStepFather(X, Y):-
dif(X, Y),
isMale(X),
not(isParent(X, Y)),
isMother(Z, Y), isHusband(X, Z).
First off, I know that sometimes "not" is "\=" or some other slash combination, so is there a better version of my "not" statement? Also, the last line is supposed to read like: "X is a StepFather of Y, if Z is a mother of Y, and X is a Husband of Z."
I want to specify the 2 Z-statements as a single idea/condition, so I put them on the same row, but does that matter? Or is there a better way of chaining two conditions that are linked to each other, but not necessarily to the other conditions?
Finally, would it be better/more elegant to use
isWife(Z, X)
instead of
isHusband(X, Z)
so that Z stays in the front of both statements?
Please let me know your feedback!
2 reasonable ways spring to mind:
stepfather_child(SF, C) :-
mother_child(M, C),
husband_wife(SF, M),
\+ father_child(SF, C).
... and:
stepfather_child_alt(SF, C) :-
dif(F, SF),
mother_father_child(M, F, C),
husband_wife(SF, M).
Some programming notes:
\+
is only safe when the variables are ground, so move it to be after clauses which will make the variables grounddif
clauses to be before they could be pointlessly-often called due to backtrackingparent
or person
and then need some other way of knowing something as fundamental as male or female, when e.g. husband_wife
or mother_father_child
makes it obvious by their placement - could make it more specific with e.g. mother_father_daughter
and mother_father_son
like_this
rather than likeThis
, so that capitalized variables stand out.