Slide 14.29: Search (cont.)
Slide 14.31: Search (cont.)
Home

Search (Cont.)


     fun( X ) :- red( X ),  car( X ).
     fun( X ) :- blue( X ), bike(X).

                                /* database of red items */
     red( apple_1 ).            /* first choice */
     red( block_1 ).
     red( car_27 ).

     car( desoto_48 ).          /* database of cars */
     car( edsel_57 ).

Search Step III
First let's retrieve a red object from the red database

     red( apple_1 ).        /* database of red items */
     red( block_1 ).
     red( car_27 ).
The first red item that we find is apple_1. This gives us the instantiation X=apple_1. Next we have to see if this is a car, so we ask the question car(apple_1). Does car(apple_1) match with our existing database of facts about cars?
     car( desoto_48 ).       /* database of cars */
     car( edsel_57 ).
The answers is that it will not. apple_1 will not match with desoto_48 or with edsel_57. So what do we do next? In such cases, Prolog backtracks in order to find another solution. Thus we go back to the red database, and see if we can find another possible solution. In this case we can
     red( apple_1 ).
     red( block_1 ).      /* second choice */
     red( car_27 ).
We can use the next clause and see if block_1 is a red car.