Self-Test 7

Accumulators
 
Where the question includes a partial program, you are advised to copy and paste this into a file. You should develop all your solutions on a machine and test them before looking at the solutions.

Deleting the nth member of a list
 
  Write a procedure called delete_nth/3 which calls an accumulator called delete_nth/4. As its name suggests, it should remove the nth element from a list, returning another list without the element. Your version of delete_nth/4 should be tail recursive.
 
 

Given the following queries, your procedure should give the following results:

     | ?- delete_nth1(1, 3, [a,b,c,d,e], List).

     List = [a,b,d,e] ? ;

     no
     | ?- delete_nth1(1, Pos, [a,b,c,d,e], [a,b,d,e]).

     Pos = 3 ? ;

     no
     | ?- delete_nth1(1, 3, List, [a,b,d,e]).

     List = [a,b,_14266,d,e] ? ;

     no