You are missing an extra case: what happens if the current item is not the one you want to delete? Here's a general idea of ββwhat needs to be done, I am not giving you a direct answer, because it looks like homework (you should use the homework tag in your question). Better fill in the blanks yourself:
(define (delete-all xx elt) (cond ((null? xx) ; base case: empty list null) ; return the empty list ((equal? elt (car xx)) ; current element needs to be removed <???>) ; ignore current element and make recursive call (else ; current element needs to be added to the list (<???> (car xx) <???>)))) ; add current element and make recursive call
Also, do not call delete in your answer, given that this is a recursive solution, instead you need to call delete-all , but with the appropriate arguments, to preserve the recursion until the base case is reached. Hint: how about cons and cdr ?
source share