Sunday 18 January 2009

Variables

Variables are string of letters, digits and underscore character. They start with an upper case letter or an underscore character:
X
X2
X_Y
_x123
_12
Variables without a name are called anonymous variables, which is written as a single underscore character.
hasachild(X):-parent(X,_).


Each time a single underscore character occurs in a clause it represents a new anonymous variable.
“Somebody_has_a_child:-parent(_,_).” is equal to,
“Somebody_has_a_child:-parent(X,Y).” but not equal to,
“Somebody_has_a_child:-parent(X,X).”
Is Ali have any children and if it is so what are their names?
?- parent(ali,Y).
Is Ali have any children?
?-parent(ali,_).

No comments:

Post a Comment