CP2003 - Tutorial 12

Prolog


  1. Which of the following are syntactically correct Prolog objects? What kind of objects are they (atom, number, variable)?
    (a) Diana
    (b) diana
    (c) 'Diana'
    (d) _diana
    (e) 'Diana goes south'
    (f) 45
    



  2. Define the relation grandchild using the parent relation.


  3. What happens if we ask Prolog:
       X = f(X).
    



  4. Define the relation
        max(X, Y, Max)
    
    so that Max is the greater of two numbers X and Y.




  5. Write a program to calculate n! (n! = 1 * 2 * ... * n-1 * n), for any positive integer n.




  6. Define the relation
         last(Item, List)
    
    so that Item is the last element of list List.




  7. Define two predicates
      evenlength(List)    and     oddlength(List)
    
    so that they are true if they argument is a list of even or odd length recursively. For example, the list [a,b,c,d] is `evenlength' and list [a,b,c] is 1oddlength'.