+1 vote
82 views

A list of $n$ elements is commonly written as a sequence of $n$ elements enclosed in a pair of square brackets. For example. $[10, 20, 30]$ is a list of three elements and $[]$ is a nil list. Five functions are defined below:

• $car (l)$ returns the first element of its argument list $l$;
• $cdr (l)$ returns the list obtained by removing the first element of the argument list $l$;
• $glue (a, l)$ returns a list $m$ such that $car (m)= a$ and $cdr (m)=l$.
• $f (x, y) \equiv$ if $x= []$ then $y$
else $glue (car (x), f (cdr (x), y))$;
• $g(x) \equiv$ if $x = []$ then $[ ]$
else $f (g (cdr (x))$, $glue (car (x), [ ]))$

What do the following compute?

(a) $f ([32, 16, 8], [9, 11, 12])$

(b) $g ([5, 1, 8, 9])$

edited | 82 views