General
Lab Material
Lab 1
Lab 2
Lab 3
Lab 4
Lab 5
Lab 6

Basic Exercises

We will start out with a couple of simple keyboard exercises so make sure that you understand how the Prolog programs that we saw before work.
  • Start Prolog and consult recognise1.pl, recognise2.pl, and haha1.pl. Using both test1 (which calls recognise1) and test2 (which calls recognise2) see whether various strings are accepted e.g

    test1([h,a,!]).
    test2([h,a,!]).
    test1([h,a,h,a,h,a,!]).

    Make sure you understand why these strings are accepted. That is, use trace to step through the execution so that you understand exactly what is going on.

  • Now restart Prolog and consult recognizs1.pl, recognise2.pl, and haha2.pl. The big difference between haha1 and haha2 is that haha2 contains a jump arc #. Now, recogniser1 does not handle jump arcs so it should not be able to handle haha2 correctly. Try out the following experiments, and make sure you understand why recognize1 gives the responses it gives:

    | ?- test1([h,a,!]).
    yes

    | ?- test1([h,a,h,a,!]).
    no

    | ?- test1([h,a,h,a,h,a,!]).
    no

    Now try these examples with test2. Again, carry out traces. Try using generate1 to generate using haha2. Now try using generate2 with haha2. Why does generate1 give a wrong response?

Back to lab 1.