I am having issues with recursions involving lists for my HW. The HW problem asks the following:
"a (pair a b) is a (make-pair x y) where x is type a and y is type b (define-struct pair (a b))
Write the function partition as described here:
partition : (a -> bool) (listof a) -> (pair (listof a) (listof a)) divide a list into two lists: - one list of the elements for which the test is true, and - a second list of the elements for which the test is false."
What I was trying to do is the following:
(define (partition test lst2)
(cond
[(null? lst2) null]
[(boolean=? #f (first(map test lst2))) (remove (first lst2) lst2) (partition test (rest lst2)))]
[else (cond (first lst2) (partition test (rest lst2)))]))
I realize that using the map function here is not the right way to to do it, but I do not really know how to keep the recursion for the 2nd case going (or the else case for that matter, since no matter what I do, it doesn't move forward). Once I get the cases for true, would I get the cases for false using not somewhere in the code? Or would I need to do something completely different? I have been stumped on this problem for a while and some guidance would be nice!
filter(gnu.org/software/mit-scheme/documentation/mit-scheme-ref/…) yet? - Benjamin Kovach