简体   繁体   中英

writing rules in prolog

I am learning Prolog and would just like to check myself: I think this question is very basic but I am just beginning.

father(X,Y)
mother(X,Y)
male(X)
female(X)
parent(X,Y)
diff(X,Y)

To write a clause for is_mother(X) is this correct?

is_mother(X):- female(X), parent(X,Y).

Thank you

is_mother(X) :- female(X), parent(X,Y).

This is technically correct in that it says, X is a mother if X is female, and X is the parent of someone (Y). In this definition, Prolog will give you a warning about Y being a "singleton" variable since you don't use its value. To avoid that warning, you can use _ or a name that starts with _ to indicate a variable whose value you don't care about and Prolog won't warn that you're not using:

is_mother(X) :- female(X), parent(X,_).

The terms female(X) and parent(X,_) assume that you have either predicates female(X) and parent(X,Y) or you have facts, such as (for example) female(sally). where sally is an "atom" (a constant in Prolog), and/or parent(sally, tom).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM