List functions with cons ======================== 1. Write the function (make-list n x) that makes a list of n x's. Assume n is a nonnegative integer. Test Cases: (make-list 0 'hi) -> '() (make-list 1 'hi) -> '(hi) (make-list 3 'hi) -> '(hi hi hi) 2. Write the function (insert-item i L value) inserts a value in L at index i. Test Cases: (insert-item 2 '(bat sat cat mat) 'hat) -> '(bat sat hat cat mat) (insert-item 0 '(1 2 3 4) 100) -> '(100 1 2 3 4) 3. Write (replace-item index L value) that replaces the item at index with value. Test Cases: (replace-item 0 '(hat mat) 'cat) -> '(cat mat) (replace-item 1 '(hat mat) 'cat) -> '(hat cat) 4. Write (my-remove item L) that removes all occurrences of item from L. Test Case: (my-remove 0 '(3 0 2 0 5) ) -> '(3 2 5) 5. Write (lput x L) that adds x to the end of the list L. Test Cases: (lput 'a '()) -> '(a) (lput 'e '(a b c d)) -> '(a b c d e) 6. Write (my-append L1 L2) that forms a new list by adding the elements of L2 to the end of L1. Test Cases: (my-append '() '(1 2)) -> '(1 2) (my-append '(3 5) '()) -> '(3 5) (my-append '(1 2 3) '(4 5)) -> '(1 2 3 4 5) 7. Write (my-filter pred L) that forms a list by collecting all the data expressions from L which have the property of pred. Test cases: (my-filter even? '(1 2 3 4)) -> '(2 4) (my-filter atom? '(1 () (3) a b)) -> '( 1 a b) (my-filter list? '(1 () (3) a b)) -> '(()(3)) (my-filter null? '(1 () (3) a b)) -> '(()) 8. Write the higher ordered function (my-map f L) that takes a function and a list and returns a new list by apply function f onto each item in L. Test Cases: (my-map abs '(-2 -1 0 1)) -> '(2 1 0 1) (my-map even? '(0 1 2 3 4)) -> '(#t #f #t #f #t 9. Write (collect-all-atoms L) that collects all the atoms in L that appear anywhere within L. Test Cases: (collect-all-atoms '(a (b ((c))) ((((d)))))) -> '(a b c d) 10. Write (remove-duplicates L) that removes the duplicates of list L. Test Cases: (remove-duplicates '(1 2 1 3 1 4)) -> '(2 3 1 4) (remove-duplicates '(hat mat sat)) -> '(hat mat sat) (remove-duplicates '()) -> '() 11. Write (my-reverse L) that reverse list L. Test Cases: (my-reverse '()) -> '() (my-reverse '(a)) -> '(a) (my-reverse '(a b c)) -> '(c b a)