10.3 Example II

Example

In this example, we match

1. person(Nick, gender(male))

with

2. person(N, gender(male))

Matching the two structures

Again, the top-level term is a structure, so we invoke rule 2. The two structures have the same functor and arity, but do their arguments match?

Matching the first argument

Nick matches N because N is a free variable, and Nick is an atomic constant (rule 3). N is bound to the atomic constant Nick.

Matching the second argument

Does

gender(male) 

(from term 1) match with

gender(male) 

(from term 2)?

Well, they are both structures, so we invoke rule 2. They both have the same functor ("gender") and arity (1), so we try to see whether their arguments match.

male (from term 1) matches male (from term 2) because they are both atomic constants and they are the same (this is rule 1).

Thus the overall result is that the matching succeeds, with the variable N bound to the value Nick.

Next

Next, we look at a third and final example.


PrevLite: 10.2 Example I
NextLite: 10.4 Example III

Prev: 10.2 Example I
Up: 10 Matching
Next: 10.4 Example III