
10 Mar 2005
CS 3243 - FOL and Prolog
Example:
Concatenate lists a and b
list procedure
cat(list a, list b)
{
list t = list u = copylist(a);
while (t.tail != nil) t = t.tail;
t.tail = b;
return u;
}
In an imperative language
In a declarative language
In a functional language
cat(a,b) º
if b = nil then a
else
cons(head(a), cat(tail(a),b))
cat([], Z,
Z).
cat([H|T], L,
[H|Z]) :- cat(T, L, Z).