Remove first occurrence of element from list

As explained here, I'm learning a limited subset of Scheme.

My task has been to sort a numerical list. To implement a simple insertion sort, I need to remove a single element from a list.

I've done the following (in the spirit of The Little Schemer):

(define remove-elem
(lambda (ll elem)
(cond
((null? ll) '())
((eq? (car ll) elem) (cdr ll))
(else
(cons (car ll) (remove-elem (cdr ll) elem))))
))


What are other ways of implementing this function?

(define (remove-elem xs elem)

Second, you are using eq?. That is the wrong checker for this problem. That function returns true if the two objects are the exact same object in memory. It could be true for primitives like ints, but it's not necessarily true. What you want to use is eqv? which will guaranteed work for numbers.