CSM-212 Exercise 1

1. Do the following unification operations succeed
or fail? If they succeed, what are the results? Attempt
these by hand before using the machine:
 
 
U                  =       [[a,b,c],d,[[e,f]]]
 
[U|V]              =       [[a,b,c],d,[[e,f]]]
 
[U,V,W]            =       [[a,b,c],d,[[e,f]]]
 
[U,V,[W|X]]        =       [[a,b,c],d,[[e,f]]]
 
[[U,[V|W]],[X,Y]]  =       [[a,b,c],d,[[e,f]]]
 
[[U,[V|W]],X,Y]    =       [[a,b,c],d,[[e,f]]]
 
[[U,[V|W]],X,[Y]]  =       [[a,b,c],d,[[e,f]]]
 


2. Using the builtin predicate name(A,S), where A is an atom and S is
a string, define a predicate a2n(A,N) which converts between a single
character and its ASCII code. 


3. Using the operator declarations

:- op(510,xfy,'-').
:- op(500,xfy,',').

find out the tree structure assigned to the following expression.

a-functor(arg1,other-arguments)

What happens if the precedences are reversed?


4. Define 

m(X,L)

which succeeds if X is a member of a list L.


5.  Define len(L,N)
 
which binds N to the length (= number of elements in) list L.

6. Define

conv(N,T) such that T is a representation for integer T

eg. conv(0,0)
conv(4,s(s(s(s(0))))).

7. Using the representation in 6. define the sum relation
so that 

sum(X,Y,N).

gives all possible pairs X and Y whose sum is N

8. Define

cat(L1,L2,L)

such that L is the result of concatenating L1 and L2.

9. Define atcat(A1,A2,A) such that A is the atom whose name
is obtained by concatenating the names of A1 and A2.


Mike Rosner (webmaster@cs.um.edu.mt)
Last modified: Thu Feb 25 15:45:57 1999