Homework 6. More Prolog.

Problem 1.

An fg-expression is a function term in which f and g are the only function symbols (other than constants). For example, f(a, b), f(a, g(b, c, d)) and g(f(a,b),g(a,b,c),e) are all fg-expressions. In this problem, you may assume that f is binary (takes two arguments), that g is ternary (has three arguments), and that an fg-expression contains no numbers or variables. You may also assume that your functions can only be given fg-expressions, i.e., no error checking is necessary.

Problem 2. The built-in Prolog predicate name(Word,List) is true iff List is a list of ASCII codes, one code for each letter in Word. Name can be used to break a word into a list of ASCII codes, and vice versa. For example,

    | ?- name(bill, List).
         List = [98,105,108,108]
    | ?- name(Word ,[98,105,108,108]).
         Word = bill

Using name, define the predicate letters(Word,List), which is true iff List is a list of the letters that make up Word. Here is a sample terminal session:

     | ?- letters(bill,List).
          List = [b,i,l,l]
     | ?- letters(Word,[b,i,l,l]).
          Word = bill

Problem 3. Do the following problems from Sethi: