Draw box-and-pointer for the values of the following expressions. Also give box and list notation.
Examine the following (incorrect) reverse
function:
Draw the box-and-pointer diagram, box notation and list notation for the result returned by the following function call:
Write expressions using lst
, head
and tail
that will return 1 when the lst
is bound to the following values:
The function list_ref
can be applied to a list xs
and a number n
, and returns the n
-th element of the list, starting counting at 0. So list_ref(list(1, 2, 3), 2)
evaluates to 3. The position of an element in the list is called its rank; we say that the number 3 has rank 2 in the list. Write a Source function called every_second
that takes a list as its only argument and returns a list containing all the elements of odd rank (i.e. every second element) from the input list.
Write a Source §2 function called sums
that takes a list of numbers as its only argument and returns a list of numbers, containing two elements: the first is the sum of all even-ranked numbers in the input list (ranks 0, 2, 4 etc), whereras the second element is the sum of all odd-ranked elements in the input list (ranks 1, 3, 5 etc).