Here is an abstract data type for lists:
$\square$ Constants: { } , the empty list
$\square$ Selectors:
First [list], the first element of the list
Rest [list], the rest of the list without its first element
$\square$ Constructors:
Prepend[list, elem], gives a new list whose first element is elem and whose rest is list
$\square$ Predicates:
ListQ [list], returns True, if list is a list
Define the following functions on lists, using rules (no loops or branches, but conditional rules if necessary). Lists may be accessed only with the given selectors and predicates.
1. join $\left[l_1, l_2\right]$ : this function joins two lists
2. flatten[list ]: this function turns a nested list into a linear list
3. count $[l, e]$ : counts how often the element $c$ occurs in the linear list $l$ (Use $===$ for testing equality)
Examples:
These two lists are simply spliced together.
Make sure to treat special cases correctly.
All inner parentheses are removed.
An empty list is removed completely
The element a occurs twice.
$$
\begin{aligned}
& \operatorname{In}[1]:=\operatorname{join}[\{a, b, c\},\{x, y\}] \\
& \text { Out }[1]=\{a, b, c, x, y\} \\
& \operatorname{In}[2]:=j o i n[\{\},\{x,\{y, z\}\}] \\
& \text { Out }[2]=\{x,\{y, z\}\} \\
& \operatorname{In}[3]:=\{1 \operatorname{atten}[\{\{a\},\{b, c\}, d\}] \\
& \text { Out }[3]=\{a, b, c, d\} \\
& \operatorname{In}[4]:=\{1 \text { atten }[\{\{\},\{\{1\}, 2\}\}] \\
& \text { Out }[4]=\{1,2\} \\
& \operatorname{In}[5]:=\operatorname{count}[\{a, b, a, x\}, a] \\
& \text { Out }[5]=2
\end{aligned}
$$
In this list it occurs only once because the $\operatorname{In}[6]:=\operatorname{count}[\{(a\}, a, b\}, a]$ list $\{a\}$ is not the same as the symbol a. Out $[6]=1$