Page 208 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 208
Artificial Intelligence
Notes /* An item qualifies to be a hardware if it qualified to be an equipment */
/*List of facts */
equipment(mouse).
equipment(keyboard).
equipment(modem).
equipment(‘web camera’).
equipment(monitor).
equipment(‘hard disk’).
/* End of program */
14.4.3 Variables
Variables are denoted by a string consisting of letters, numbers and underscore characters, and
beginning with an upper-case letter or underscore. Variables closely resemble variables in logic
in that they are placeholders for arbitrary terms. A variable can become instantiated (bound to
equal a specific term) via unification. A single underscore (_) denotes an anonymous variable
and means “any term”. Unlike other variables, the underscore does not represent the same
value everywhere it occurs within a predicate definition. A variable name contains letters,
digits, and underscores. It begins with a capital letter or an underscore mark.
Example: Some examples of variables are Result, _total, and _a123.
There are two types of variables:
Free variable: A variable whose value is unknown to the Prolog program
Bound variable: A variable whose value is set
To understand the different variable types, consider the example of the following set of
facts:
likes(trope, reading).
likes(bb, swimming).
likes(trope, football).
likes(Saj, reading).
Consider that the rule for deducing from the above facts is:
likes(X, reading) and likes(X, football).
ProLog searches from left to right, so the first subgoal is:
likes(X, reading)
In the above statement of subgoal the first argument is X, which is a free variable and the value
in second argument is reading. ProLog attempts to satisfy the subgoal with facts that contain
reading as the second argument. In the example the match found is:
likes(trope, reading).
The X variable is now bound to the value, trope; the ProLog execution then shifts to the next
subgoal, which is:
likes(trope, swimming).
The above statement shows that the variable X has been substituted with the value, trope.
202 LOVELY PROFESSIONAL UNIVERSITY