I can get the filter works, but it does not do it destructively. Below are the starting code and test cases:
(define (filter! f s)
;;Your solution
Test cases:
(define (big x) (> x 5))
(define ints (list 1 10 3 8 4 7))
(define ints1 (cdr ints))
(define filtered-ints (filter! big ints))
filtered-ints
; expect (10 8 7)
(eq? filtered-ints ints1) ; expect #t
Could anyone help please?
This should work:
I adapted the above from the
filter!procedure in SRFI 1: List Library. Notice that if you’re using Racket a thing or two needs to be modified for the above code to work properly. For example, Racket no longer supportsset-cdr!and you’ll have to useset-mcdr!instead.