I am writing a program that does some list manipulations in scheme (R5RS).
I am trying to create a procedure that will remove n
items at index i
of a list L
.
I have written procedures that return all but the first n
items in L
and a procedure that returns only the first n
elements of L
.
I was able to write a procedure that removes the ith
item of L
but cannot figure out how to remove n
items. This is my remove procedure:
(define (remove L i)
(cond ((null? L)'())
((= i 0) (cdr L))
(else (cons (car L) (remove (cdr L) (- i 1))))))
`(remove '(1 2 3 4 5) 2)` -> (1 2 4 5)
I am struggling to come up with a procedure (remove L i n)
that will do the following:
(remove '(1 2 3 4 5) 2 2) -> (1 2 5)