title: Scheme function applying a function to all elements in a list, no matter how deep, while preserving the structure of the list
body: <p>Hey, I'm working on a homework question about applying a function to every element in a list, going as deep as needed.</p>
  
  <p>I am getting a error when calling (fun (car l)), that </p>
  
  <pre><code>mcar: expects argument of type &lt;mutable-pair&gt;; given 5
  </code></pre>
  
  <p>and yet when I just call (fun l) i get the error
  +: expects type  as 1st argument, given: (5); other arguments were: 1</p>
  
  <pre><code>   (define (map-gen fun l)
      (if (null? fun) l 
          (if (null? l) '()
              (if (list? (car l))
                  (append (map-gen fun (cdr l)) (map-gen fun (car l)))
                  (append (map-gen fun (cdr l)) (fun (car l)))))))
  </code></pre>
  
  <p>Any and all help is appreciated!</p>
  
  <p>edit: This is when calling the function like so:</p>
  
  <pre><code>(map-gen (lambda (x) (+ x 1))'(1 (2 (3 4))(((5)))))
  </code></pre>