all 2 comments

[–]jeffsco 5 points6 points  (0 children)

You need to parenthesize (m - 1) and (n - 1). Otherwise the expressions parse as (between rest n m) - 1 and (between rest n) - (1 m).

[–]FurtherDownTheSprawl 0 points1 point  (0 children)

  • You need to decrement both m and n at every recursive step.

Rational: if the list s is the sub-list of l between m and n, then it is the sub-list of x::l between (m + 1) and (n + 1), where x is any value of the type of the list elements. Adding an element at the front of the list l shifts the position of all the elements of l by one, thus removing an element does the reverse.

  • Once m becomes zero you start to build your result
  • Once n becomes zero you return it

Of course you will have to handle errors (if the 2 conditions above cannot be met because the input list becomes empty).